2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
70 #include "texcompress_etc.h"
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.0F
;
520 newImage
[i
* texComponents
+ k
] = 1.0F
;
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
,
854 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
858 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
859 const GLvoid
*srcAddr
,
860 const struct gl_pixelstore_attrib
*srcPacking
)
862 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
863 const GLubyte
*srctype2ubyte
, *swap
;
864 GLubyte map
[4], src2base
[6], base2rgba
[6];
866 const GLint srcRowStride
=
867 _mesa_image_row_stride(srcPacking
, srcWidth
,
868 srcFormat
, GL_UNSIGNED_BYTE
);
869 const GLint srcImageStride
870 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
872 const GLubyte
*srcImage
873 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
874 srcWidth
, srcHeight
, srcFormat
,
875 GL_UNSIGNED_BYTE
, 0, 0, 0);
879 /* Translate from src->baseInternal->GL_RGBA->dst. This will
880 * correctly deal with RGBA->RGB->RGBA conversions where the final
881 * A value must be 0xff regardless of the incoming alpha values.
883 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
884 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
885 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
886 srctype2ubyte
= type_mapping(srcType
);
889 for (i
= 0; i
< 4; i
++)
890 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
892 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
894 if (srcComponents
== dstComponents
&&
895 srcRowStride
== dstRowStride
&&
896 srcRowStride
== srcWidth
* srcComponents
&&
898 /* 1 and 2D images only */
899 GLubyte
*dstImage
= dstSlices
[0]
900 + dstYoffset
* dstRowStride
901 + dstXoffset
* dstComponents
;
902 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
903 srcWidth
* srcHeight
);
907 for (img
= 0; img
< srcDepth
; img
++) {
908 const GLubyte
*srcRow
= srcImage
;
909 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
910 + dstYoffset
* dstRowStride
911 + dstXoffset
* dstComponents
;
912 for (row
= 0; row
< srcHeight
; row
++) {
913 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
914 dstRow
+= dstRowStride
;
915 srcRow
+= srcRowStride
;
917 srcImage
+= srcImageStride
;
924 * Teximage storage routine for when a simple memcpy will do.
925 * No pixel transfer operations or special texel encodings allowed.
926 * 1D, 2D and 3D images supported.
929 memcpy_texture(struct gl_context
*ctx
,
932 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
935 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
936 GLenum srcFormat
, GLenum srcType
,
937 const GLvoid
*srcAddr
,
938 const struct gl_pixelstore_attrib
*srcPacking
)
940 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
942 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
943 srcWidth
, srcHeight
, srcFormat
, srcType
);
944 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
945 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
946 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
947 const GLint bytesPerRow
= srcWidth
* texelBytes
;
949 if (dstRowStride
== srcRowStride
&&
950 dstRowStride
== bytesPerRow
) {
951 /* memcpy image by image */
953 for (img
= 0; img
< srcDepth
; img
++) {
954 GLubyte
*dstImage
= dstSlices
[dstZoffset
+ img
]
955 + dstYoffset
* dstRowStride
956 + dstXoffset
* texelBytes
;
957 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
,
958 bytesPerRow
* srcHeight
);
959 srcImage
+= srcImageStride
;
963 /* memcpy row by row */
965 for (img
= 0; img
< srcDepth
; img
++) {
966 const GLubyte
*srcRow
= srcImage
;
967 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
968 + dstYoffset
* dstRowStride
969 + dstXoffset
* texelBytes
;
970 for (row
= 0; row
< srcHeight
; row
++) {
971 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
972 dstRow
+= dstRowStride
;
973 srcRow
+= srcRowStride
;
975 srcImage
+= srcImageStride
;
983 * Store a 32-bit integer or float depth component texture image.
986 _mesa_texstore_z32(TEXSTORE_PARAMS
)
988 const GLuint depthScale
= 0xffffffff;
989 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
992 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
993 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
994 ASSERT(texelBytes
== sizeof(GLuint
));
996 if (dstFormat
== MESA_FORMAT_Z32
)
997 dstType
= GL_UNSIGNED_INT
;
1001 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1002 ctx
->Pixel
.DepthBias
== 0.0f
&&
1003 !srcPacking
->SwapBytes
&&
1004 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1005 srcFormat
== GL_DEPTH_COMPONENT
&&
1006 srcType
== dstType
) {
1007 /* simple memcpy path */
1008 memcpy_texture(ctx
, dims
,
1009 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1010 dstRowStride
, dstSlices
,
1011 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1012 srcAddr
, srcPacking
);
1017 for (img
= 0; img
< srcDepth
; img
++) {
1018 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1019 + dstYoffset
* dstRowStride
1020 + dstXoffset
* texelBytes
;
1021 for (row
= 0; row
< srcHeight
; row
++) {
1022 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1023 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1024 _mesa_unpack_depth_span(ctx
, srcWidth
,
1026 depthScale
, srcType
, src
, srcPacking
);
1027 dstRow
+= dstRowStride
;
1036 * Store a 24-bit integer depth component texture image.
1039 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1041 const GLuint depthScale
= 0xffffff;
1042 const GLuint texelBytes
= 4;
1045 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1050 for (img
= 0; img
< srcDepth
; img
++) {
1051 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1052 + dstYoffset
* dstRowStride
1053 + dstXoffset
* texelBytes
;
1054 for (row
= 0; row
< srcHeight
; row
++) {
1055 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1056 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1057 _mesa_unpack_depth_span(ctx
, srcWidth
,
1058 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1059 depthScale
, srcType
, src
, srcPacking
);
1060 dstRow
+= dstRowStride
;
1069 * Store a 24-bit integer depth component texture image.
1072 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1074 const GLuint depthScale
= 0xffffff;
1075 const GLuint texelBytes
= 4;
1078 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1083 for (img
= 0; img
< srcDepth
; img
++) {
1084 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1085 + dstYoffset
* dstRowStride
1086 + dstXoffset
* texelBytes
;
1087 for (row
= 0; row
< srcHeight
; row
++) {
1088 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1089 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1090 GLuint
*dst
= (GLuint
*) dstRow
;
1092 _mesa_unpack_depth_span(ctx
, srcWidth
,
1093 GL_UNSIGNED_INT
, dst
,
1094 depthScale
, srcType
, src
, srcPacking
);
1095 for (i
= 0; i
< srcWidth
; i
++)
1097 dstRow
+= dstRowStride
;
1106 * Store a 16-bit integer depth component texture image.
1109 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1111 const GLuint depthScale
= 0xffff;
1112 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1114 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1115 ASSERT(texelBytes
== sizeof(GLushort
));
1117 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1118 ctx
->Pixel
.DepthBias
== 0.0f
&&
1119 !srcPacking
->SwapBytes
&&
1120 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1121 srcFormat
== GL_DEPTH_COMPONENT
&&
1122 srcType
== GL_UNSIGNED_SHORT
) {
1123 /* simple memcpy path */
1124 memcpy_texture(ctx
, dims
,
1125 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1126 dstRowStride
, dstSlices
,
1127 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1128 srcAddr
, srcPacking
);
1133 for (img
= 0; img
< srcDepth
; img
++) {
1134 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1135 + dstYoffset
* dstRowStride
1136 + dstXoffset
* texelBytes
;
1137 for (row
= 0; row
< srcHeight
; row
++) {
1138 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1139 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1140 GLushort
*dst16
= (GLushort
*) dstRow
;
1141 _mesa_unpack_depth_span(ctx
, srcWidth
,
1142 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1143 srcType
, src
, srcPacking
);
1144 dstRow
+= dstRowStride
;
1153 * Store an rgb565 or rgb565_rev texture image.
1156 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1158 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1159 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1161 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1162 dstFormat
== MESA_FORMAT_RGB565_REV
);
1163 ASSERT(texelBytes
== 2);
1165 if (!ctx
->_ImageTransferState
&&
1166 !srcPacking
->SwapBytes
&&
1167 dstFormat
== MESA_FORMAT_RGB565
&&
1168 baseInternalFormat
== GL_RGB
&&
1169 srcFormat
== GL_RGB
&&
1170 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1171 /* simple memcpy path */
1172 memcpy_texture(ctx
, dims
,
1173 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1174 dstRowStride
, dstSlices
,
1175 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1176 srcAddr
, srcPacking
);
1178 else if (!ctx
->_ImageTransferState
&&
1179 !srcPacking
->SwapBytes
&&
1180 baseInternalFormat
== GL_RGB
&&
1181 srcFormat
== GL_RGB
&&
1182 srcType
== GL_UNSIGNED_BYTE
&&
1184 /* do optimized tex store */
1185 const GLint srcRowStride
=
1186 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1187 const GLubyte
*src
= (const GLubyte
*)
1188 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1189 srcFormat
, srcType
, 0, 0, 0);
1190 GLubyte
*dst
= dstSlices
[0]
1191 + dstYoffset
* dstRowStride
1192 + dstXoffset
* texelBytes
;
1194 for (row
= 0; row
< srcHeight
; row
++) {
1195 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1196 GLushort
*dstUS
= (GLushort
*) dst
;
1197 /* check for byteswapped format */
1198 if (dstFormat
== MESA_FORMAT_RGB565
) {
1199 for (col
= 0; col
< srcWidth
; col
++) {
1200 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1205 for (col
= 0; col
< srcWidth
; col
++) {
1206 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1210 dst
+= dstRowStride
;
1211 src
+= srcRowStride
;
1216 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1219 srcWidth
, srcHeight
, srcDepth
,
1220 srcFormat
, srcType
, srcAddr
,
1222 const GLubyte
*src
= tempImage
;
1223 GLint img
, row
, col
;
1226 for (img
= 0; img
< srcDepth
; img
++) {
1227 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1228 + dstYoffset
* dstRowStride
1229 + dstXoffset
* texelBytes
;
1230 for (row
= 0; row
< srcHeight
; row
++) {
1231 GLushort
*dstUS
= (GLushort
*) dstRow
;
1232 /* check for byteswapped format */
1233 if (dstFormat
== MESA_FORMAT_RGB565
) {
1234 for (col
= 0; col
< srcWidth
; col
++) {
1235 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1242 for (col
= 0; col
< srcWidth
; col
++) {
1243 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1249 dstRow
+= dstRowStride
;
1252 free((void *) tempImage
);
1259 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1262 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1264 const GLboolean littleEndian
= _mesa_little_endian();
1265 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1266 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1268 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1269 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1270 dstFormat
== MESA_FORMAT_RGBX8888
||
1271 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1272 ASSERT(texelBytes
== 4);
1274 if (!ctx
->_ImageTransferState
&&
1275 !srcPacking
->SwapBytes
&&
1276 (dstFormat
== MESA_FORMAT_RGBA8888
||
1277 dstFormat
== MESA_FORMAT_RGBX8888
) &&
1278 baseInternalFormat
== GL_RGBA
&&
1279 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1280 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1281 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1282 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1283 /* simple memcpy path */
1284 memcpy_texture(ctx
, dims
,
1285 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1286 dstRowStride
, dstSlices
,
1287 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1288 srcAddr
, srcPacking
);
1290 else if (!ctx
->_ImageTransferState
&&
1291 !srcPacking
->SwapBytes
&&
1292 (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1293 dstFormat
== MESA_FORMAT_RGBX8888_REV
) &&
1294 baseInternalFormat
== GL_RGBA
&&
1295 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1296 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1297 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1298 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1299 /* simple memcpy path */
1300 memcpy_texture(ctx
, dims
,
1301 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1302 dstRowStride
, dstSlices
,
1303 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1304 srcAddr
, srcPacking
);
1306 else if (!ctx
->_ImageTransferState
&&
1307 (srcType
== GL_UNSIGNED_BYTE
||
1308 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1309 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1310 can_swizzle(baseInternalFormat
) &&
1311 can_swizzle(srcFormat
)) {
1315 /* dstmap - how to swizzle from RGBA to dst format:
1317 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1318 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1319 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1320 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1333 _mesa_swizzle_ubyte_image(ctx
, dims
,
1338 dstXoffset
, dstYoffset
, dstZoffset
,
1339 dstRowStride
, dstSlices
,
1340 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1345 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1348 srcWidth
, srcHeight
, srcDepth
,
1349 srcFormat
, srcType
, srcAddr
,
1351 const GLubyte
*src
= tempImage
;
1352 GLint img
, row
, col
;
1355 for (img
= 0; img
< srcDepth
; img
++) {
1356 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1357 + dstYoffset
* dstRowStride
1358 + dstXoffset
* texelBytes
;
1359 for (row
= 0; row
< srcHeight
; row
++) {
1360 GLuint
*dstUI
= (GLuint
*) dstRow
;
1361 if (dstFormat
== MESA_FORMAT_RGBA8888
||
1362 dstFormat
== MESA_FORMAT_RGBX8888
) {
1363 for (col
= 0; col
< srcWidth
; col
++) {
1364 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1372 for (col
= 0; col
< srcWidth
; col
++) {
1373 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1380 dstRow
+= dstRowStride
;
1383 free((void *) tempImage
);
1390 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1392 const GLboolean littleEndian
= _mesa_little_endian();
1393 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1394 const GLenum baseFormat
= GL_RGBA
;
1396 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1397 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1398 dstFormat
== MESA_FORMAT_XRGB8888
||
1399 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1400 ASSERT(texelBytes
== 4);
1402 if (!ctx
->_ImageTransferState
&&
1403 !srcPacking
->SwapBytes
&&
1404 (dstFormat
== MESA_FORMAT_ARGB8888
||
1405 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1406 baseInternalFormat
== GL_RGBA
&&
1407 srcFormat
== GL_BGRA
&&
1408 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1409 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1410 /* simple memcpy path (little endian) */
1411 memcpy_texture(ctx
, dims
,
1412 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1413 dstRowStride
, dstSlices
,
1414 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1415 srcAddr
, srcPacking
);
1417 else if (!ctx
->_ImageTransferState
&&
1418 !srcPacking
->SwapBytes
&&
1419 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1420 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1421 baseInternalFormat
== GL_RGBA
&&
1422 srcFormat
== GL_BGRA
&&
1423 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1424 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1425 /* simple memcpy path (big endian) */
1426 memcpy_texture(ctx
, dims
,
1427 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1428 dstRowStride
, dstSlices
,
1429 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1430 srcAddr
, srcPacking
);
1432 else if (!ctx
->_ImageTransferState
&&
1433 !srcPacking
->SwapBytes
&&
1434 (dstFormat
== MESA_FORMAT_ARGB8888
||
1435 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1436 srcFormat
== GL_RGB
&&
1437 (baseInternalFormat
== GL_RGBA
||
1438 baseInternalFormat
== GL_RGB
) &&
1439 srcType
== GL_UNSIGNED_BYTE
) {
1441 for (img
= 0; img
< srcDepth
; img
++) {
1442 const GLint srcRowStride
=
1443 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1444 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1445 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1446 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1447 + dstYoffset
* dstRowStride
1448 + dstXoffset
* texelBytes
;
1449 for (row
= 0; row
< srcHeight
; row
++) {
1450 GLuint
*d4
= (GLuint
*) dstRow
;
1451 for (col
= 0; col
< srcWidth
; col
++) {
1452 d4
[col
] = PACK_COLOR_8888(0xff,
1453 srcRow
[col
* 3 + RCOMP
],
1454 srcRow
[col
* 3 + GCOMP
],
1455 srcRow
[col
* 3 + BCOMP
]);
1457 dstRow
+= dstRowStride
;
1458 srcRow
+= srcRowStride
;
1462 else if (!ctx
->_ImageTransferState
&&
1463 !srcPacking
->SwapBytes
&&
1464 dstFormat
== MESA_FORMAT_ARGB8888
&&
1465 srcFormat
== GL_RGBA
&&
1466 baseInternalFormat
== GL_RGBA
&&
1467 srcType
== GL_UNSIGNED_BYTE
) {
1468 /* same as above case, but src data has alpha too */
1469 GLint img
, row
, col
;
1470 /* For some reason, streaming copies to write-combined regions
1471 * are extremely sensitive to the characteristics of how the
1472 * source data is retrieved. By reordering the source reads to
1473 * be in-order, the speed of this operation increases by half.
1474 * Strangely the same isn't required for the RGB path, above.
1476 for (img
= 0; img
< srcDepth
; img
++) {
1477 const GLint srcRowStride
=
1478 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1479 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1480 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1481 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1482 + dstYoffset
* dstRowStride
1483 + dstXoffset
* texelBytes
;
1484 for (row
= 0; row
< srcHeight
; row
++) {
1485 GLuint
*d4
= (GLuint
*) dstRow
;
1486 for (col
= 0; col
< srcWidth
; col
++) {
1487 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1488 srcRow
[col
* 4 + RCOMP
],
1489 srcRow
[col
* 4 + GCOMP
],
1490 srcRow
[col
* 4 + BCOMP
]);
1492 dstRow
+= dstRowStride
;
1493 srcRow
+= srcRowStride
;
1497 else if (!ctx
->_ImageTransferState
&&
1498 (srcType
== GL_UNSIGNED_BYTE
||
1499 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1500 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1501 can_swizzle(baseInternalFormat
) &&
1502 can_swizzle(srcFormat
)) {
1506 /* dstmap - how to swizzle from RGBA to dst format:
1508 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1509 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1510 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1511 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1512 dstmap
[3] = 3; /* alpha */
1513 dstmap
[2] = 0; /* red */
1514 dstmap
[1] = 1; /* green */
1515 dstmap
[0] = 2; /* blue */
1518 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1519 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1520 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1521 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1528 _mesa_swizzle_ubyte_image(ctx
, dims
,
1533 dstXoffset
, dstYoffset
, dstZoffset
,
1536 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1541 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1544 srcWidth
, srcHeight
, srcDepth
,
1545 srcFormat
, srcType
, srcAddr
,
1547 const GLubyte
*src
= tempImage
;
1548 GLint img
, row
, col
;
1551 for (img
= 0; img
< srcDepth
; img
++) {
1552 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1553 + dstYoffset
* dstRowStride
1554 + dstXoffset
* texelBytes
;
1555 for (row
= 0; row
< srcHeight
; row
++) {
1556 GLuint
*dstUI
= (GLuint
*) dstRow
;
1557 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1558 for (col
= 0; col
< srcWidth
; col
++) {
1559 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1566 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1567 for (col
= 0; col
< srcWidth
; col
++) {
1568 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1576 for (col
= 0; col
< srcWidth
; col
++) {
1577 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1584 dstRow
+= dstRowStride
;
1587 free((void *) tempImage
);
1594 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1596 const GLboolean littleEndian
= _mesa_little_endian();
1597 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1598 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1600 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1601 ASSERT(texelBytes
== 3);
1603 if (!ctx
->_ImageTransferState
&&
1604 !srcPacking
->SwapBytes
&&
1605 baseInternalFormat
== GL_RGB
&&
1606 srcFormat
== GL_BGR
&&
1607 srcType
== GL_UNSIGNED_BYTE
&&
1609 /* simple memcpy path */
1610 memcpy_texture(ctx
, dims
,
1611 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1612 dstRowStride
, dstSlices
,
1613 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1614 srcAddr
, srcPacking
);
1616 else if (!ctx
->_ImageTransferState
&&
1617 !srcPacking
->SwapBytes
&&
1618 srcFormat
== GL_RGBA
&&
1619 srcType
== GL_UNSIGNED_BYTE
) {
1620 /* extract RGB from RGBA */
1621 GLint img
, row
, col
;
1622 for (img
= 0; img
< srcDepth
; img
++) {
1623 const GLint srcRowStride
=
1624 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1625 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1626 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1627 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1628 + dstYoffset
* dstRowStride
1629 + dstXoffset
* texelBytes
;
1630 for (row
= 0; row
< srcHeight
; row
++) {
1631 for (col
= 0; col
< srcWidth
; col
++) {
1632 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1633 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1634 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1636 dstRow
+= dstRowStride
;
1637 srcRow
+= srcRowStride
;
1641 else if (!ctx
->_ImageTransferState
&&
1642 srcType
== GL_UNSIGNED_BYTE
&&
1643 can_swizzle(baseInternalFormat
) &&
1644 can_swizzle(srcFormat
)) {
1648 /* dstmap - how to swizzle from RGBA to dst format:
1653 dstmap
[3] = ONE
; /* ? */
1655 _mesa_swizzle_ubyte_image(ctx
, dims
,
1660 dstXoffset
, dstYoffset
, dstZoffset
,
1661 dstRowStride
, dstSlices
,
1662 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1667 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1670 srcWidth
, srcHeight
, srcDepth
,
1671 srcFormat
, srcType
, srcAddr
,
1673 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1674 GLint img
, row
, col
;
1677 for (img
= 0; img
< srcDepth
; img
++) {
1678 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1679 + dstYoffset
* dstRowStride
1680 + dstXoffset
* texelBytes
;
1681 for (row
= 0; row
< srcHeight
; row
++) {
1684 for (col
= 0; col
< srcWidth
; col
++) {
1685 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1686 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1687 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1692 for (col
= 0; col
< srcWidth
; col
++) {
1693 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1694 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1695 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1700 for (col
= 0; col
< srcWidth
; col
++) {
1701 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1702 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1703 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1707 dstRow
+= dstRowStride
;
1710 free((void *) tempImage
);
1717 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1719 const GLboolean littleEndian
= _mesa_little_endian();
1720 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1721 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1723 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1724 ASSERT(texelBytes
== 3);
1726 if (!ctx
->_ImageTransferState
&&
1727 !srcPacking
->SwapBytes
&&
1728 baseInternalFormat
== GL_RGB
&&
1729 srcFormat
== GL_RGB
&&
1730 srcType
== GL_UNSIGNED_BYTE
&&
1732 /* simple memcpy path */
1733 memcpy_texture(ctx
, dims
,
1734 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1735 dstRowStride
, dstSlices
,
1736 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1737 srcAddr
, srcPacking
);
1739 else if (!ctx
->_ImageTransferState
&&
1740 !srcPacking
->SwapBytes
&&
1741 srcFormat
== GL_RGBA
&&
1742 srcType
== GL_UNSIGNED_BYTE
) {
1743 /* extract BGR from RGBA */
1745 for (img
= 0; img
< srcDepth
; img
++) {
1746 const GLint srcRowStride
=
1747 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1748 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1749 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1750 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1751 + dstYoffset
* dstRowStride
1752 + dstXoffset
* texelBytes
;
1753 for (row
= 0; row
< srcHeight
; row
++) {
1754 for (col
= 0; col
< srcWidth
; col
++) {
1755 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1756 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1757 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1759 dstRow
+= dstRowStride
;
1760 srcRow
+= srcRowStride
;
1764 else if (!ctx
->_ImageTransferState
&&
1765 srcType
== GL_UNSIGNED_BYTE
&&
1766 can_swizzle(baseInternalFormat
) &&
1767 can_swizzle(srcFormat
)) {
1771 /* dstmap - how to swizzle from RGBA to dst format:
1776 dstmap
[3] = ONE
; /* ? */
1778 _mesa_swizzle_ubyte_image(ctx
, dims
,
1783 dstXoffset
, dstYoffset
, dstZoffset
,
1784 dstRowStride
, dstSlices
,
1785 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1790 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1793 srcWidth
, srcHeight
, srcDepth
,
1794 srcFormat
, srcType
, srcAddr
,
1796 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1797 GLint img
, row
, col
;
1800 for (img
= 0; img
< srcDepth
; img
++) {
1801 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1802 + dstYoffset
* dstRowStride
1803 + dstXoffset
* texelBytes
;
1804 for (row
= 0; row
< srcHeight
; row
++) {
1805 for (col
= 0; col
< srcWidth
; col
++) {
1806 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1807 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1808 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1811 dstRow
+= dstRowStride
;
1814 free((void *) tempImage
);
1821 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1823 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1824 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1826 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1827 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1828 ASSERT(texelBytes
== 2);
1830 if (!ctx
->_ImageTransferState
&&
1831 !srcPacking
->SwapBytes
&&
1832 dstFormat
== MESA_FORMAT_ARGB4444
&&
1833 baseInternalFormat
== GL_RGBA
&&
1834 srcFormat
== GL_BGRA
&&
1835 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1836 /* simple memcpy path */
1837 memcpy_texture(ctx
, dims
,
1838 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1839 dstRowStride
, dstSlices
,
1840 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1841 srcAddr
, srcPacking
);
1845 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1848 srcWidth
, srcHeight
, srcDepth
,
1849 srcFormat
, srcType
, srcAddr
,
1851 const GLubyte
*src
= tempImage
;
1852 GLint img
, row
, col
;
1855 for (img
= 0; img
< srcDepth
; img
++) {
1856 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1857 + dstYoffset
* dstRowStride
1858 + dstXoffset
* texelBytes
;
1859 for (row
= 0; row
< srcHeight
; row
++) {
1860 GLushort
*dstUS
= (GLushort
*) dstRow
;
1861 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1862 for (col
= 0; col
< srcWidth
; col
++) {
1863 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1871 for (col
= 0; col
< srcWidth
; col
++) {
1872 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1879 dstRow
+= dstRowStride
;
1882 free((void *) tempImage
);
1888 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1890 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1891 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1893 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1894 ASSERT(texelBytes
== 2);
1896 if (!ctx
->_ImageTransferState
&&
1897 !srcPacking
->SwapBytes
&&
1898 dstFormat
== MESA_FORMAT_RGBA5551
&&
1899 baseInternalFormat
== GL_RGBA
&&
1900 srcFormat
== GL_RGBA
&&
1901 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1902 /* simple memcpy path */
1903 memcpy_texture(ctx
, dims
,
1904 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1905 dstRowStride
, dstSlices
,
1906 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1907 srcAddr
, srcPacking
);
1911 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1914 srcWidth
, srcHeight
, srcDepth
,
1915 srcFormat
, srcType
, srcAddr
,
1917 const GLubyte
*src
=tempImage
;
1918 GLint img
, row
, col
;
1921 for (img
= 0; img
< srcDepth
; img
++) {
1922 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1923 + dstYoffset
* dstRowStride
1924 + dstXoffset
* texelBytes
;
1925 for (row
= 0; row
< srcHeight
; row
++) {
1926 GLushort
*dstUS
= (GLushort
*) dstRow
;
1927 for (col
= 0; col
< srcWidth
; col
++) {
1928 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1934 dstRow
+= dstRowStride
;
1937 free((void *) tempImage
);
1943 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1945 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1946 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1948 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1949 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1950 ASSERT(texelBytes
== 2);
1952 if (!ctx
->_ImageTransferState
&&
1953 !srcPacking
->SwapBytes
&&
1954 dstFormat
== MESA_FORMAT_ARGB1555
&&
1955 baseInternalFormat
== GL_RGBA
&&
1956 srcFormat
== GL_BGRA
&&
1957 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1958 /* simple memcpy path */
1959 memcpy_texture(ctx
, dims
,
1960 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1961 dstRowStride
, dstSlices
,
1962 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1963 srcAddr
, srcPacking
);
1967 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1970 srcWidth
, srcHeight
, srcDepth
,
1971 srcFormat
, srcType
, srcAddr
,
1973 const GLubyte
*src
=tempImage
;
1974 GLint img
, row
, col
;
1977 for (img
= 0; img
< srcDepth
; img
++) {
1978 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1979 + dstYoffset
* dstRowStride
1980 + dstXoffset
* texelBytes
;
1981 for (row
= 0; row
< srcHeight
; row
++) {
1982 GLushort
*dstUS
= (GLushort
*) dstRow
;
1983 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1984 for (col
= 0; col
< srcWidth
; col
++) {
1985 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
1993 for (col
= 0; col
< srcWidth
; col
++) {
1994 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
2001 dstRow
+= dstRowStride
;
2004 free((void *) tempImage
);
2011 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2013 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2014 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2016 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2017 ASSERT(texelBytes
== 4);
2019 if (!ctx
->_ImageTransferState
&&
2020 !srcPacking
->SwapBytes
&&
2021 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2022 srcFormat
== GL_BGRA
&&
2023 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2024 baseInternalFormat
== GL_RGBA
) {
2025 /* simple memcpy path */
2026 memcpy_texture(ctx
, dims
,
2027 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2028 dstRowStride
, dstSlices
,
2029 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2030 srcAddr
, srcPacking
);
2034 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2037 srcWidth
, srcHeight
, srcDepth
,
2038 srcFormat
, srcType
, srcAddr
,
2040 ctx
->_ImageTransferState
);
2041 const GLfloat
*src
= tempImage
;
2042 GLint img
, row
, col
;
2045 for (img
= 0; img
< srcDepth
; img
++) {
2046 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2047 + dstYoffset
* dstRowStride
2048 + dstXoffset
* texelBytes
;
2049 if (baseInternalFormat
== GL_RGBA
) {
2050 for (row
= 0; row
< srcHeight
; row
++) {
2051 GLuint
*dstUI
= (GLuint
*) dstRow
;
2052 for (col
= 0; col
< srcWidth
; col
++) {
2055 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2056 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2057 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2058 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2059 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2062 dstRow
+= dstRowStride
;
2064 } else if (baseInternalFormat
== GL_RGB
) {
2065 for (row
= 0; row
< srcHeight
; row
++) {
2066 GLuint
*dstUI
= (GLuint
*) dstRow
;
2067 for (col
= 0; col
< srcWidth
; col
++) {
2070 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2071 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2072 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2073 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2076 dstRow
+= dstRowStride
;
2082 free((void *) tempImage
);
2089 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2092 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2094 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2095 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2097 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2098 ASSERT(texelBytes
== 1);
2102 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2105 srcWidth
, srcHeight
, srcDepth
,
2106 srcFormat
, srcType
, srcAddr
,
2108 const GLubyte
*src
= tempImage
;
2109 GLint img
, row
, col
;
2112 for (img
= 0; img
< srcDepth
; img
++) {
2113 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2114 + dstYoffset
* dstRowStride
2115 + dstXoffset
* texelBytes
;
2116 for (row
= 0; row
< srcHeight
; row
++) {
2117 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2118 for (col
= 0; col
< srcWidth
; col
++) {
2119 /* src[0] is luminance, src[1] is alpha */
2120 dstUS
[col
] = PACK_COLOR_44( src
[1],
2124 dstRow
+= dstRowStride
;
2127 free((void *) tempImage
);
2134 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2137 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2139 const GLboolean littleEndian
= _mesa_little_endian();
2140 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2141 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2143 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2144 dstFormat
== MESA_FORMAT_AL88_REV
||
2145 dstFormat
== MESA_FORMAT_RG88
||
2146 dstFormat
== MESA_FORMAT_RG88_REV
);
2147 ASSERT(texelBytes
== 2);
2149 if (!ctx
->_ImageTransferState
&&
2150 !srcPacking
->SwapBytes
&&
2151 ((dstFormat
== MESA_FORMAT_AL88
&&
2152 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2153 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2154 (dstFormat
== MESA_FORMAT_RG88
&&
2155 baseInternalFormat
== srcFormat
)) &&
2156 srcType
== GL_UNSIGNED_BYTE
&&
2158 /* simple memcpy path */
2159 memcpy_texture(ctx
, dims
,
2160 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2161 dstRowStride
, dstSlices
,
2162 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2163 srcAddr
, srcPacking
);
2165 else if (!ctx
->_ImageTransferState
&&
2167 srcType
== GL_UNSIGNED_BYTE
&&
2168 can_swizzle(baseInternalFormat
) &&
2169 can_swizzle(srcFormat
)) {
2172 /* dstmap - how to swizzle from RGBA to dst format:
2174 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2175 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2176 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2186 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2187 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2196 dstmap
[2] = ZERO
; /* ? */
2197 dstmap
[3] = ONE
; /* ? */
2199 _mesa_swizzle_ubyte_image(ctx
, dims
,
2204 dstXoffset
, dstYoffset
, dstZoffset
,
2205 dstRowStride
, dstSlices
,
2206 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2211 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2214 srcWidth
, srcHeight
, srcDepth
,
2215 srcFormat
, srcType
, srcAddr
,
2217 const GLubyte
*src
= tempImage
;
2218 GLint img
, row
, col
;
2221 for (img
= 0; img
< srcDepth
; img
++) {
2222 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2223 + dstYoffset
* dstRowStride
2224 + dstXoffset
* texelBytes
;
2225 for (row
= 0; row
< srcHeight
; row
++) {
2226 GLushort
*dstUS
= (GLushort
*) dstRow
;
2227 if (dstFormat
== MESA_FORMAT_AL88
||
2228 dstFormat
== MESA_FORMAT_RG88
) {
2229 for (col
= 0; col
< srcWidth
; col
++) {
2230 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2231 dstUS
[col
] = PACK_COLOR_88( src
[1],
2237 for (col
= 0; col
< srcWidth
; col
++) {
2238 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2239 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2244 dstRow
+= dstRowStride
;
2247 free((void *) tempImage
);
2254 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2257 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2259 const GLboolean littleEndian
= _mesa_little_endian();
2260 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2261 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2263 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2264 dstFormat
== MESA_FORMAT_AL1616_REV
||
2265 dstFormat
== MESA_FORMAT_RG1616
||
2266 dstFormat
== MESA_FORMAT_RG1616_REV
);
2267 ASSERT(texelBytes
== 4);
2269 if (!ctx
->_ImageTransferState
&&
2270 !srcPacking
->SwapBytes
&&
2271 ((dstFormat
== MESA_FORMAT_AL1616
&&
2272 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2273 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2274 (dstFormat
== MESA_FORMAT_RG1616
&&
2275 baseInternalFormat
== srcFormat
)) &&
2276 srcType
== GL_UNSIGNED_SHORT
&&
2278 /* simple memcpy path */
2279 memcpy_texture(ctx
, dims
,
2280 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2281 dstRowStride
, dstSlices
,
2282 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2283 srcAddr
, srcPacking
);
2287 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2290 srcWidth
, srcHeight
, srcDepth
,
2291 srcFormat
, srcType
, srcAddr
,
2293 ctx
->_ImageTransferState
);
2294 const GLfloat
*src
= tempImage
;
2295 GLint img
, row
, col
;
2298 for (img
= 0; img
< srcDepth
; img
++) {
2299 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2300 + dstYoffset
* dstRowStride
2301 + dstXoffset
* texelBytes
;
2302 for (row
= 0; row
< srcHeight
; row
++) {
2303 GLuint
*dstUI
= (GLuint
*) dstRow
;
2304 if (dstFormat
== MESA_FORMAT_AL1616
||
2305 dstFormat
== MESA_FORMAT_RG1616
) {
2306 for (col
= 0; col
< srcWidth
; col
++) {
2309 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2310 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2311 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2316 for (col
= 0; col
< srcWidth
; col
++) {
2319 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2320 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2321 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2325 dstRow
+= dstRowStride
;
2328 free((void *) tempImage
);
2334 /* Texstore for R16, A16, L16, I16. */
2336 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2338 const GLboolean littleEndian
= _mesa_little_endian();
2339 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2340 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2342 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2343 dstFormat
== MESA_FORMAT_A16
||
2344 dstFormat
== MESA_FORMAT_L16
||
2345 dstFormat
== MESA_FORMAT_I16
);
2346 ASSERT(texelBytes
== 2);
2348 if (!ctx
->_ImageTransferState
&&
2349 !srcPacking
->SwapBytes
&&
2350 baseInternalFormat
== srcFormat
&&
2351 srcType
== GL_UNSIGNED_SHORT
&&
2353 /* simple memcpy path */
2354 memcpy_texture(ctx
, dims
,
2355 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2356 dstRowStride
, dstSlices
,
2357 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2358 srcAddr
, srcPacking
);
2362 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2365 srcWidth
, srcHeight
, srcDepth
,
2366 srcFormat
, srcType
, srcAddr
,
2368 ctx
->_ImageTransferState
);
2369 const GLfloat
*src
= tempImage
;
2370 GLint img
, row
, col
;
2373 for (img
= 0; img
< srcDepth
; img
++) {
2374 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2375 + dstYoffset
* dstRowStride
2376 + dstXoffset
* texelBytes
;
2377 for (row
= 0; row
< srcHeight
; row
++) {
2378 GLushort
*dstUS
= (GLushort
*) dstRow
;
2379 for (col
= 0; col
< srcWidth
; col
++) {
2382 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2386 dstRow
+= dstRowStride
;
2389 free((void *) tempImage
);
2396 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2398 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2399 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2401 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2402 ASSERT(texelBytes
== 8);
2404 if (!ctx
->_ImageTransferState
&&
2405 !srcPacking
->SwapBytes
&&
2406 baseInternalFormat
== GL_RGBA
&&
2407 srcFormat
== GL_RGBA
&&
2408 srcType
== GL_UNSIGNED_SHORT
) {
2409 /* simple memcpy path */
2410 memcpy_texture(ctx
, dims
,
2411 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2412 dstRowStride
, dstSlices
,
2413 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2414 srcAddr
, srcPacking
);
2418 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2421 srcWidth
, srcHeight
, srcDepth
,
2422 srcFormat
, srcType
, srcAddr
,
2424 ctx
->_ImageTransferState
);
2425 const GLfloat
*src
= tempImage
;
2426 GLint img
, row
, col
;
2429 for (img
= 0; img
< srcDepth
; img
++) {
2430 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2431 + dstYoffset
* dstRowStride
2432 + dstXoffset
* texelBytes
;
2433 for (row
= 0; row
< srcHeight
; row
++) {
2434 GLushort
*dstUS
= (GLushort
*) dstRow
;
2435 for (col
= 0; col
< srcWidth
; col
++) {
2436 GLushort r
, g
, b
, a
;
2438 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2439 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2440 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2441 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2448 dstRow
+= dstRowStride
;
2451 free((void *) tempImage
);
2458 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2460 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2461 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2463 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2464 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2466 if (!ctx
->_ImageTransferState
&&
2467 !srcPacking
->SwapBytes
&&
2468 baseInternalFormat
== GL_RGBA
&&
2469 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2470 srcFormat
== GL_RGBA
&&
2471 srcType
== GL_SHORT
) {
2472 /* simple memcpy path */
2473 memcpy_texture(ctx
, dims
,
2474 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2475 dstRowStride
, dstSlices
,
2476 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2477 srcAddr
, srcPacking
);
2481 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2484 srcWidth
, srcHeight
, srcDepth
,
2485 srcFormat
, srcType
, srcAddr
,
2487 ctx
->_ImageTransferState
);
2488 const GLfloat
*src
= tempImage
;
2489 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2490 GLint img
, row
, col
;
2495 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2496 * 3 or 4 components/pixel here.
2498 for (img
= 0; img
< srcDepth
; img
++) {
2499 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2500 + dstYoffset
* dstRowStride
2501 + dstXoffset
* texelBytes
;
2502 for (row
= 0; row
< srcHeight
; row
++) {
2503 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2504 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2505 for (col
= 0; col
< srcWidth
; col
++) {
2507 for (c
= 0; c
< comps
; c
++) {
2509 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2510 dstRowS
[col
* comps
+ c
] = p
;
2513 dstRow
+= dstRowStride
;
2514 src
+= 4 * srcWidth
;
2516 for (col
= 0; col
< srcWidth
; col
++) {
2518 for (c
= 0; c
< comps
; c
++) {
2520 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2521 dstRowS
[col
* comps
+ c
] = p
;
2524 dstRow
+= dstRowStride
;
2525 src
+= 3 * srcWidth
;
2529 free((void *) tempImage
);
2536 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2538 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2539 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2541 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2542 ASSERT(texelBytes
== 1);
2544 if (!ctx
->_ImageTransferState
&&
2545 !srcPacking
->SwapBytes
&&
2546 baseInternalFormat
== GL_RGB
&&
2547 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2548 /* simple memcpy path */
2549 memcpy_texture(ctx
, dims
,
2550 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2551 dstRowStride
, dstSlices
,
2552 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2553 srcAddr
, srcPacking
);
2557 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2560 srcWidth
, srcHeight
, srcDepth
,
2561 srcFormat
, srcType
, srcAddr
,
2563 const GLubyte
*src
= tempImage
;
2564 GLint img
, row
, col
;
2567 for (img
= 0; img
< srcDepth
; img
++) {
2568 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2569 + dstYoffset
* dstRowStride
2570 + dstXoffset
* texelBytes
;
2571 for (row
= 0; row
< srcHeight
; row
++) {
2572 for (col
= 0; col
< srcWidth
; col
++) {
2573 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2578 dstRow
+= dstRowStride
;
2581 free((void *) tempImage
);
2588 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2591 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2593 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2594 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2596 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2597 dstFormat
== MESA_FORMAT_L8
||
2598 dstFormat
== MESA_FORMAT_I8
||
2599 dstFormat
== MESA_FORMAT_R8
);
2600 ASSERT(texelBytes
== 1);
2602 if (!ctx
->_ImageTransferState
&&
2603 !srcPacking
->SwapBytes
&&
2604 baseInternalFormat
== srcFormat
&&
2605 srcType
== GL_UNSIGNED_BYTE
) {
2606 /* simple memcpy path */
2607 memcpy_texture(ctx
, dims
,
2608 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2609 dstRowStride
, dstSlices
,
2610 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2611 srcAddr
, srcPacking
);
2613 else if (!ctx
->_ImageTransferState
&&
2614 srcType
== GL_UNSIGNED_BYTE
&&
2615 can_swizzle(baseInternalFormat
) &&
2616 can_swizzle(srcFormat
)) {
2619 /* dstmap - how to swizzle from RGBA to dst format:
2621 if (dstFormat
== MESA_FORMAT_A8
) {
2627 dstmap
[1] = ZERO
; /* ? */
2628 dstmap
[2] = ZERO
; /* ? */
2629 dstmap
[3] = ONE
; /* ? */
2631 _mesa_swizzle_ubyte_image(ctx
, dims
,
2636 dstXoffset
, dstYoffset
, dstZoffset
,
2637 dstRowStride
, dstSlices
,
2638 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2643 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2646 srcWidth
, srcHeight
, srcDepth
,
2647 srcFormat
, srcType
, srcAddr
,
2649 const GLubyte
*src
= tempImage
;
2650 GLint img
, row
, col
;
2653 for (img
= 0; img
< srcDepth
; img
++) {
2654 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2655 + dstYoffset
* dstRowStride
2656 + dstXoffset
* texelBytes
;
2657 for (row
= 0; row
< srcHeight
; row
++) {
2658 for (col
= 0; col
< srcWidth
; col
++) {
2659 dstRow
[col
] = src
[col
];
2661 dstRow
+= dstRowStride
;
2665 free((void *) tempImage
);
2673 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2676 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2678 const GLboolean littleEndian
= _mesa_little_endian();
2679 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2681 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2683 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2684 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2685 ASSERT(texelBytes
== 2);
2686 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2687 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2688 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2689 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2690 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2692 /* always just memcpy since no pixel transfer ops apply */
2693 memcpy_texture(ctx
, dims
,
2694 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2695 dstRowStride
, dstSlices
,
2696 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2697 srcAddr
, srcPacking
);
2699 /* Check if we need byte swapping */
2700 /* XXX the logic here _might_ be wrong */
2701 if (srcPacking
->SwapBytes
^
2702 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2703 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2706 for (img
= 0; img
< srcDepth
; img
++) {
2707 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2708 + dstYoffset
* dstRowStride
2709 + dstXoffset
* texelBytes
;
2710 for (row
= 0; row
< srcHeight
; row
++) {
2711 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2712 dstRow
+= dstRowStride
;
2720 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2722 const GLboolean littleEndian
= _mesa_little_endian();
2723 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2725 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2726 ASSERT(texelBytes
== 2);
2727 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2728 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2729 (srcFormat
== GL_DUDV_ATI
));
2730 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2732 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2734 /* simple memcpy path */
2735 memcpy_texture(ctx
, dims
,
2736 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2737 dstRowStride
, dstSlices
,
2738 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2739 srcAddr
, srcPacking
);
2741 else if (srcType
== GL_BYTE
) {
2744 /* dstmap - how to swizzle from RGBA to dst format:
2754 dstmap
[2] = ZERO
; /* ? */
2755 dstmap
[3] = ONE
; /* ? */
2757 _mesa_swizzle_ubyte_image(ctx
, dims
,
2758 GL_LUMINANCE_ALPHA
, /* hack */
2759 GL_UNSIGNED_BYTE
, /* hack */
2760 GL_LUMINANCE_ALPHA
, /* hack */
2762 dstXoffset
, dstYoffset
, dstZoffset
,
2763 dstRowStride
, dstSlices
,
2764 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2768 /* general path - note this is defined for 2d textures only */
2769 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2770 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2771 srcFormat
, srcType
);
2772 GLbyte
*tempImage
, *dst
, *src
;
2775 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2776 * components
* sizeof(GLbyte
));
2780 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2781 srcWidth
, srcHeight
,
2786 for (row
= 0; row
< srcHeight
; row
++) {
2787 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2788 dst
, srcFormat
, srcType
, src
,
2790 dst
+= srcWidth
* components
;
2795 dst
= (GLbyte
*) dstSlices
[0]
2796 + dstYoffset
* dstRowStride
2797 + dstXoffset
* texelBytes
;
2798 for (row
= 0; row
< srcHeight
; row
++) {
2799 memcpy(dst
, src
, srcWidth
* texelBytes
);
2800 dst
+= dstRowStride
;
2801 src
+= srcWidth
* texelBytes
;
2803 free((void *) tempImage
);
2810 * Store a texture in a signed normalized 8-bit format.
2813 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2815 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2816 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2818 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2819 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2820 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2821 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2822 ASSERT(texelBytes
== 1);
2824 if (!ctx
->_ImageTransferState
&&
2825 !srcPacking
->SwapBytes
&&
2826 baseInternalFormat
== srcFormat
&&
2827 srcType
== GL_BYTE
) {
2828 /* simple memcpy path */
2829 memcpy_texture(ctx
, dims
,
2830 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2831 dstRowStride
, dstSlices
,
2832 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2833 srcAddr
, srcPacking
);
2837 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2840 srcWidth
, srcHeight
, srcDepth
,
2841 srcFormat
, srcType
, srcAddr
,
2843 ctx
->_ImageTransferState
);
2844 const GLfloat
*src
= tempImage
;
2845 GLint img
, row
, col
;
2848 for (img
= 0; img
< srcDepth
; img
++) {
2849 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
2850 + dstYoffset
* dstRowStride
2851 + dstXoffset
* texelBytes
;
2852 for (row
= 0; row
< srcHeight
; row
++) {
2853 for (col
= 0; col
< srcWidth
; col
++) {
2854 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2856 dstRow
+= dstRowStride
;
2860 free((void *) tempImage
);
2867 * Store a texture in a signed normalized two-channel 16-bit format.
2870 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2872 const GLboolean littleEndian
= _mesa_little_endian();
2873 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2874 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2876 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2877 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2878 ASSERT(texelBytes
== 2);
2880 if (!ctx
->_ImageTransferState
&&
2881 !srcPacking
->SwapBytes
&&
2882 baseInternalFormat
== srcFormat
&&
2883 srcType
== GL_BYTE
&&
2885 /* simple memcpy path */
2886 memcpy_texture(ctx
, dims
,
2887 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2888 dstRowStride
, dstSlices
,
2889 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2890 srcAddr
, srcPacking
);
2894 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2897 srcWidth
, srcHeight
, srcDepth
,
2898 srcFormat
, srcType
, srcAddr
,
2900 ctx
->_ImageTransferState
);
2901 const GLfloat
*src
= tempImage
;
2902 GLint img
, row
, col
;
2905 for (img
= 0; img
< srcDepth
; img
++) {
2906 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
2907 + dstYoffset
* dstRowStride
2908 + dstXoffset
* texelBytes
;
2909 for (row
= 0; row
< srcHeight
; row
++) {
2910 GLbyte
*dst
= dstRow
;
2911 for (col
= 0; col
< srcWidth
; col
++) {
2912 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2913 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2917 dstRow
+= dstRowStride
;
2920 free((void *) tempImage
);
2925 /* Texstore for signed R16, A16, L16, I16. */
2927 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2929 const GLboolean littleEndian
= _mesa_little_endian();
2930 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2931 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2933 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2934 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2935 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2936 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2937 ASSERT(texelBytes
== 2);
2939 if (!ctx
->_ImageTransferState
&&
2940 !srcPacking
->SwapBytes
&&
2941 baseInternalFormat
== srcFormat
&&
2942 srcType
== GL_SHORT
&&
2944 /* simple memcpy path */
2945 memcpy_texture(ctx
, dims
,
2946 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2947 dstRowStride
, dstSlices
,
2948 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2949 srcAddr
, srcPacking
);
2953 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2956 srcWidth
, srcHeight
, srcDepth
,
2957 srcFormat
, srcType
, srcAddr
,
2959 ctx
->_ImageTransferState
);
2960 const GLfloat
*src
= tempImage
;
2961 GLint img
, row
, col
;
2964 for (img
= 0; img
< srcDepth
; img
++) {
2965 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2966 + dstYoffset
* dstRowStride
2967 + dstXoffset
* texelBytes
;
2968 for (row
= 0; row
< srcHeight
; row
++) {
2969 GLshort
*dstUS
= (GLshort
*) dstRow
;
2970 for (col
= 0; col
< srcWidth
; col
++) {
2973 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2977 dstRow
+= dstRowStride
;
2980 free((void *) tempImage
);
2986 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2989 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2991 const GLboolean littleEndian
= _mesa_little_endian();
2992 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2993 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2995 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2996 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2997 ASSERT(texelBytes
== 4);
2999 if (!ctx
->_ImageTransferState
&&
3000 !srcPacking
->SwapBytes
&&
3001 baseInternalFormat
== srcFormat
&&
3002 srcType
== GL_SHORT
&&
3004 /* simple memcpy path */
3005 memcpy_texture(ctx
, dims
,
3006 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3007 dstRowStride
, dstSlices
,
3008 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3009 srcAddr
, srcPacking
);
3013 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3016 srcWidth
, srcHeight
, srcDepth
,
3017 srcFormat
, srcType
, srcAddr
,
3019 ctx
->_ImageTransferState
);
3020 const GLfloat
*src
= tempImage
;
3021 GLint img
, row
, col
;
3024 for (img
= 0; img
< srcDepth
; img
++) {
3025 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3026 + dstYoffset
* dstRowStride
3027 + dstXoffset
* texelBytes
;
3028 for (row
= 0; row
< srcHeight
; row
++) {
3029 GLshort
*dst
= (GLshort
*) dstRow
;
3030 for (col
= 0; col
< srcWidth
; col
++) {
3033 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
3034 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
3040 dstRow
+= dstRowStride
;
3043 free((void *) tempImage
);
3049 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
3052 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
3054 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3055 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3057 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
3058 ASSERT(texelBytes
== 4);
3062 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3065 srcWidth
, srcHeight
, srcDepth
,
3066 srcFormat
, srcType
, srcAddr
,
3068 ctx
->_ImageTransferState
);
3069 const GLfloat
*srcRow
= tempImage
;
3070 GLint img
, row
, col
;
3073 for (img
= 0; img
< srcDepth
; img
++) {
3074 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
3075 + dstYoffset
* dstRowStride
3076 + dstXoffset
* texelBytes
;
3077 for (row
= 0; row
< srcHeight
; row
++) {
3078 GLbyte
*dst
= dstRow
;
3079 for (col
= 0; col
< srcWidth
; col
++) {
3080 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3081 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3082 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3087 dstRow
+= dstRowStride
;
3090 free((void *) tempImage
);
3098 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3099 * MESA_FORMAT_SIGNED_RGBA8888_REV
3102 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3104 const GLboolean littleEndian
= _mesa_little_endian();
3105 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3106 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3108 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3109 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3110 ASSERT(texelBytes
== 4);
3112 if (!ctx
->_ImageTransferState
&&
3113 !srcPacking
->SwapBytes
&&
3114 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3115 baseInternalFormat
== GL_RGBA
&&
3116 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3117 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3118 /* simple memcpy path */
3119 memcpy_texture(ctx
, dims
,
3120 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3121 dstRowStride
, dstSlices
,
3122 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3123 srcAddr
, srcPacking
);
3125 else if (!ctx
->_ImageTransferState
&&
3126 !srcPacking
->SwapBytes
&&
3127 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3128 baseInternalFormat
== GL_RGBA
&&
3129 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3130 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3131 /* simple memcpy path */
3132 memcpy_texture(ctx
, dims
,
3133 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3134 dstRowStride
, dstSlices
,
3135 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3136 srcAddr
, srcPacking
);
3140 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3143 srcWidth
, srcHeight
, srcDepth
,
3144 srcFormat
, srcType
, srcAddr
,
3146 ctx
->_ImageTransferState
);
3147 const GLfloat
*srcRow
= tempImage
;
3148 GLint img
, row
, col
;
3151 for (img
= 0; img
< srcDepth
; img
++) {
3152 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
3153 + dstYoffset
* dstRowStride
3154 + dstXoffset
* texelBytes
;
3155 for (row
= 0; row
< srcHeight
; row
++) {
3156 GLbyte
*dst
= dstRow
;
3157 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3158 for (col
= 0; col
< srcWidth
; col
++) {
3159 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3160 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3161 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3162 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3168 for (col
= 0; col
< srcWidth
; col
++) {
3169 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3170 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3171 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3172 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3177 dstRow
+= dstRowStride
;
3180 free((void *) tempImage
);
3187 * Store a combined depth/stencil texture image.
3190 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3192 const GLuint depthScale
= 0xffffff;
3193 const GLint srcRowStride
3194 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3197 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3198 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3199 srcFormat
== GL_DEPTH_COMPONENT
||
3200 srcFormat
== GL_STENCIL_INDEX
);
3201 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3203 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3204 ctx
->Pixel
.DepthBias
== 0.0f
&&
3205 !srcPacking
->SwapBytes
) {
3207 memcpy_texture(ctx
, dims
,
3208 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3209 dstRowStride
, dstSlices
,
3210 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3211 srcAddr
, srcPacking
);
3213 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3214 srcFormat
== GL_STENCIL_INDEX
) {
3215 /* In case we only upload depth we need to preserve the stencil */
3216 for (img
= 0; img
< srcDepth
; img
++) {
3217 GLuint
*dstRow
= (GLuint
*) (dstSlices
[dstZoffset
+ img
]
3218 + dstYoffset
* dstRowStride
3221 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3222 srcWidth
, srcHeight
,
3225 for (row
= 0; row
< srcHeight
; row
++) {
3226 GLuint depth
[MAX_WIDTH
];
3227 GLubyte stencil
[MAX_WIDTH
];
3229 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3231 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3232 keepstencil
= GL_TRUE
;
3234 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3235 keepdepth
= GL_TRUE
;
3238 if (keepdepth
== GL_FALSE
)
3239 /* the 24 depth bits will be in the low position: */
3240 _mesa_unpack_depth_span(ctx
, srcWidth
,
3241 GL_UNSIGNED_INT
, /* dst type */
3242 keepstencil
? depth
: dstRow
, /* dst addr */
3244 srcType
, src
, srcPacking
);
3246 if (keepstencil
== GL_FALSE
)
3247 /* get the 8-bit stencil values */
3248 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3249 GL_UNSIGNED_BYTE
, /* dst type */
3250 stencil
, /* dst addr */
3251 srcType
, src
, srcPacking
,
3252 ctx
->_ImageTransferState
);
3254 for (i
= 0; i
< srcWidth
; i
++) {
3256 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3258 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3261 src
+= srcRowStride
;
3262 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3271 * Store a combined depth/stencil texture image.
3274 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3276 const GLuint depthScale
= 0xffffff;
3277 const GLint srcRowStride
3278 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3281 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3282 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3283 srcFormat
== GL_DEPTH_COMPONENT
||
3284 srcFormat
== GL_STENCIL_INDEX
);
3285 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3286 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3288 for (img
= 0; img
< srcDepth
; img
++) {
3289 GLuint
*dstRow
= (GLuint
*) (dstSlices
[dstZoffset
+ img
]
3290 + dstYoffset
* dstRowStride
3293 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3294 srcWidth
, srcHeight
,
3297 for (row
= 0; row
< srcHeight
; row
++) {
3298 GLuint depth
[MAX_WIDTH
];
3299 GLubyte stencil
[MAX_WIDTH
];
3301 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3303 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3304 keepstencil
= GL_TRUE
;
3306 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3307 keepdepth
= GL_TRUE
;
3310 if (keepdepth
== GL_FALSE
)
3311 /* the 24 depth bits will be in the low position: */
3312 _mesa_unpack_depth_span(ctx
, srcWidth
,
3313 GL_UNSIGNED_INT
, /* dst type */
3314 keepstencil
? depth
: dstRow
, /* dst addr */
3316 srcType
, src
, srcPacking
);
3318 if (keepstencil
== GL_FALSE
)
3319 /* get the 8-bit stencil values */
3320 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3321 GL_UNSIGNED_BYTE
, /* dst type */
3322 stencil
, /* dst addr */
3323 srcType
, src
, srcPacking
,
3324 ctx
->_ImageTransferState
);
3326 /* merge stencil values into depth values */
3327 for (i
= 0; i
< srcWidth
; i
++) {
3329 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3331 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3334 src
+= srcRowStride
;
3335 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3343 * Store simple 8-bit/value stencil texture data.
3346 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3348 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3349 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3351 if (!ctx
->_ImageTransferState
&&
3352 !srcPacking
->SwapBytes
&&
3353 baseInternalFormat
== srcFormat
&&
3354 srcType
== GL_UNSIGNED_BYTE
) {
3355 /* simple memcpy path */
3356 memcpy_texture(ctx
, dims
,
3357 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3358 dstRowStride
, dstSlices
,
3359 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3360 srcAddr
, srcPacking
);
3363 const GLint srcRowStride
3364 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3367 for (img
= 0; img
< srcDepth
; img
++) {
3368 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3369 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3372 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3373 srcWidth
, srcHeight
,
3376 for (row
= 0; row
< srcHeight
; row
++) {
3377 GLubyte stencil
[MAX_WIDTH
];
3380 /* get the 8-bit stencil values */
3381 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3382 GL_UNSIGNED_BYTE
, /* dst type */
3383 stencil
, /* dst addr */
3384 srcType
, src
, srcPacking
,
3385 ctx
->_ImageTransferState
);
3386 /* merge stencil values into depth values */
3387 for (i
= 0; i
< srcWidth
; i
++)
3388 dstRow
[i
] = stencil
[i
];
3390 src
+= srcRowStride
;
3391 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3402 * Store an image in any of the formats:
3403 * _mesa_texformat_rgba_float32
3404 * _mesa_texformat_rgb_float32
3405 * _mesa_texformat_alpha_float32
3406 * _mesa_texformat_luminance_float32
3407 * _mesa_texformat_luminance_alpha_float32
3408 * _mesa_texformat_intensity_float32
3411 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3413 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3414 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3415 const GLint components
= _mesa_components_in_format(baseFormat
);
3417 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3418 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3419 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3420 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3421 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3422 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3423 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3424 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3425 ASSERT(baseInternalFormat
== GL_RGBA
||
3426 baseInternalFormat
== GL_RGB
||
3427 baseInternalFormat
== GL_ALPHA
||
3428 baseInternalFormat
== GL_LUMINANCE
||
3429 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3430 baseInternalFormat
== GL_INTENSITY
||
3431 baseInternalFormat
== GL_RED
||
3432 baseInternalFormat
== GL_RG
);
3433 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3435 if (!ctx
->_ImageTransferState
&&
3436 !srcPacking
->SwapBytes
&&
3437 baseInternalFormat
== srcFormat
&&
3438 baseInternalFormat
== baseFormat
&&
3439 srcType
== GL_FLOAT
) {
3440 /* simple memcpy path */
3441 memcpy_texture(ctx
, dims
,
3442 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3443 dstRowStride
, dstSlices
,
3444 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3445 srcAddr
, srcPacking
);
3449 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3452 srcWidth
, srcHeight
, srcDepth
,
3453 srcFormat
, srcType
, srcAddr
,
3455 ctx
->_ImageTransferState
);
3456 const GLfloat
*srcRow
= tempImage
;
3461 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3462 for (img
= 0; img
< srcDepth
; img
++) {
3463 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3464 + dstYoffset
* dstRowStride
3465 + dstXoffset
* texelBytes
;
3466 for (row
= 0; row
< srcHeight
; row
++) {
3467 memcpy(dstRow
, srcRow
, bytesPerRow
);
3468 dstRow
+= dstRowStride
;
3469 srcRow
+= srcWidth
* components
;
3473 free((void *) tempImage
);
3481 * As above, but store 16-bit floats.
3484 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3486 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3487 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3488 const GLint components
= _mesa_components_in_format(baseFormat
);
3490 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3491 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3492 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3493 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3494 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3495 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3496 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3497 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3498 ASSERT(baseInternalFormat
== GL_RGBA
||
3499 baseInternalFormat
== GL_RGB
||
3500 baseInternalFormat
== GL_ALPHA
||
3501 baseInternalFormat
== GL_LUMINANCE
||
3502 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3503 baseInternalFormat
== GL_INTENSITY
||
3504 baseInternalFormat
== GL_RED
||
3505 baseInternalFormat
== GL_RG
);
3506 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3508 if (!ctx
->_ImageTransferState
&&
3509 !srcPacking
->SwapBytes
&&
3510 baseInternalFormat
== srcFormat
&&
3511 baseInternalFormat
== baseFormat
&&
3512 srcType
== GL_HALF_FLOAT_ARB
) {
3513 /* simple memcpy path */
3514 memcpy_texture(ctx
, dims
,
3515 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3516 dstRowStride
, dstSlices
,
3517 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3518 srcAddr
, srcPacking
);
3522 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3525 srcWidth
, srcHeight
, srcDepth
,
3526 srcFormat
, srcType
, srcAddr
,
3528 ctx
->_ImageTransferState
);
3529 const GLfloat
*src
= tempImage
;
3533 for (img
= 0; img
< srcDepth
; img
++) {
3534 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3535 + dstYoffset
* dstRowStride
3536 + dstXoffset
* texelBytes
;
3537 for (row
= 0; row
< srcHeight
; row
++) {
3538 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3540 for (i
= 0; i
< srcWidth
* components
; i
++) {
3541 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3543 dstRow
+= dstRowStride
;
3544 src
+= srcWidth
* components
;
3548 free((void *) tempImage
);
3554 /* non-normalized, signed int8 */
3556 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3558 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3559 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3560 const GLint components
= _mesa_components_in_format(baseFormat
);
3562 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3563 dstFormat
== MESA_FORMAT_RG_INT8
||
3564 dstFormat
== MESA_FORMAT_RGB_INT8
||
3565 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3566 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3567 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3568 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3569 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3570 ASSERT(baseInternalFormat
== GL_RGBA
||
3571 baseInternalFormat
== GL_RGB
||
3572 baseInternalFormat
== GL_ALPHA
||
3573 baseInternalFormat
== GL_LUMINANCE
||
3574 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3575 baseInternalFormat
== GL_INTENSITY
);
3576 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3578 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3579 * to integer formats.
3581 if (!srcPacking
->SwapBytes
&&
3582 baseInternalFormat
== srcFormat
&&
3583 srcType
== GL_BYTE
) {
3584 /* simple memcpy path */
3585 memcpy_texture(ctx
, dims
,
3586 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3587 dstRowStride
, dstSlices
,
3588 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3589 srcAddr
, srcPacking
);
3593 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3596 srcWidth
, srcHeight
, srcDepth
,
3597 srcFormat
, srcType
, srcAddr
,
3599 const GLfloat
*src
= tempImage
;
3603 for (img
= 0; img
< srcDepth
; img
++) {
3604 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3605 + dstYoffset
* dstRowStride
3606 + dstXoffset
* texelBytes
;
3607 for (row
= 0; row
< srcHeight
; row
++) {
3608 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3610 for (i
= 0; i
< srcWidth
* components
; i
++) {
3611 dstTexel
[i
] = (GLbyte
) src
[i
];
3613 dstRow
+= dstRowStride
;
3614 src
+= srcWidth
* components
;
3618 free((void *) tempImage
);
3624 /* non-normalized, signed int16 */
3626 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3628 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3629 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3630 const GLint components
= _mesa_components_in_format(baseFormat
);
3632 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3633 dstFormat
== MESA_FORMAT_RG_INT16
||
3634 dstFormat
== MESA_FORMAT_RGB_INT16
||
3635 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3636 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3637 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3638 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3639 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3640 ASSERT(baseInternalFormat
== GL_RGBA
||
3641 baseInternalFormat
== GL_RGB
||
3642 baseInternalFormat
== GL_ALPHA
||
3643 baseInternalFormat
== GL_LUMINANCE
||
3644 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3645 baseInternalFormat
== GL_INTENSITY
);
3646 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3648 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3649 * to integer formats.
3651 if (!srcPacking
->SwapBytes
&&
3652 baseInternalFormat
== srcFormat
&&
3653 srcType
== GL_SHORT
) {
3654 /* simple memcpy path */
3655 memcpy_texture(ctx
, dims
,
3656 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3657 dstRowStride
, dstSlices
,
3658 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3659 srcAddr
, srcPacking
);
3663 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3666 srcWidth
, srcHeight
, srcDepth
,
3667 srcFormat
, srcType
, srcAddr
,
3669 const GLfloat
*src
= tempImage
;
3673 for (img
= 0; img
< srcDepth
; img
++) {
3674 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3675 + dstYoffset
* dstRowStride
3676 + dstXoffset
* texelBytes
;
3677 for (row
= 0; row
< srcHeight
; row
++) {
3678 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3680 for (i
= 0; i
< srcWidth
* components
; i
++) {
3681 dstTexel
[i
] = (GLint
) src
[i
];
3683 dstRow
+= dstRowStride
;
3684 src
+= srcWidth
* components
;
3688 free((void *) tempImage
);
3694 /* non-normalized, signed int32 */
3696 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3698 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3699 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3700 const GLint components
= _mesa_components_in_format(baseFormat
);
3702 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3703 dstFormat
== MESA_FORMAT_RG_INT32
||
3704 dstFormat
== MESA_FORMAT_RGB_INT32
||
3705 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3706 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3707 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3708 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3709 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3710 ASSERT(baseInternalFormat
== GL_RGBA
||
3711 baseInternalFormat
== GL_RGB
||
3712 baseInternalFormat
== GL_ALPHA
||
3713 baseInternalFormat
== GL_LUMINANCE
||
3714 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3715 baseInternalFormat
== GL_INTENSITY
);
3716 ASSERT(texelBytes
== components
* sizeof(GLint
));
3718 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3719 * to integer formats.
3721 if (!srcPacking
->SwapBytes
&&
3722 baseInternalFormat
== srcFormat
&&
3723 srcType
== GL_INT
) {
3724 /* simple memcpy path */
3725 memcpy_texture(ctx
, dims
,
3726 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3727 dstRowStride
, dstSlices
,
3728 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3729 srcAddr
, srcPacking
);
3733 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3736 srcWidth
, srcHeight
, srcDepth
,
3737 srcFormat
, srcType
, srcAddr
,
3739 const GLfloat
*src
= tempImage
;
3743 for (img
= 0; img
< srcDepth
; img
++) {
3744 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3745 + dstYoffset
* dstRowStride
3746 + dstXoffset
* texelBytes
;
3747 for (row
= 0; row
< srcHeight
; row
++) {
3748 GLint
*dstTexel
= (GLint
*) dstRow
;
3750 for (i
= 0; i
< srcWidth
* components
; i
++) {
3751 dstTexel
[i
] = (GLint
) src
[i
];
3753 dstRow
+= dstRowStride
;
3754 src
+= srcWidth
* components
;
3758 free((void *) tempImage
);
3764 /* non-normalized, unsigned int8 */
3766 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3768 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3769 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3770 const GLint components
= _mesa_components_in_format(baseFormat
);
3772 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3773 dstFormat
== MESA_FORMAT_RG_UINT8
||
3774 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3775 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3776 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3777 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3778 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3779 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3780 ASSERT(baseInternalFormat
== GL_RGBA
||
3781 baseInternalFormat
== GL_RGB
||
3782 baseInternalFormat
== GL_ALPHA
||
3783 baseInternalFormat
== GL_LUMINANCE
||
3784 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3785 baseInternalFormat
== GL_INTENSITY
);
3786 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3788 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3789 * to integer formats.
3791 if (!srcPacking
->SwapBytes
&&
3792 baseInternalFormat
== srcFormat
&&
3793 srcType
== GL_UNSIGNED_BYTE
) {
3794 /* simple memcpy path */
3795 memcpy_texture(ctx
, dims
,
3796 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3797 dstRowStride
, dstSlices
,
3798 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3799 srcAddr
, srcPacking
);
3803 const GLuint
*tempImage
=
3804 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3805 srcWidth
, srcHeight
, srcDepth
,
3806 srcFormat
, srcType
, srcAddr
, srcPacking
);
3807 const GLuint
*src
= tempImage
;
3811 for (img
= 0; img
< srcDepth
; img
++) {
3812 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3813 + dstYoffset
* dstRowStride
3814 + dstXoffset
* texelBytes
;
3815 for (row
= 0; row
< srcHeight
; row
++) {
3816 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3818 for (i
= 0; i
< srcWidth
* components
; i
++) {
3819 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3821 dstRow
+= dstRowStride
;
3822 src
+= srcWidth
* components
;
3826 free((void *) tempImage
);
3832 /* non-normalized, unsigned int16 */
3834 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3836 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3837 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3838 const GLint components
= _mesa_components_in_format(baseFormat
);
3840 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3841 dstFormat
== MESA_FORMAT_RG_UINT16
||
3842 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3843 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3844 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3845 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3846 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3847 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3848 ASSERT(baseInternalFormat
== GL_RGBA
||
3849 baseInternalFormat
== GL_RGB
||
3850 baseInternalFormat
== GL_ALPHA
||
3851 baseInternalFormat
== GL_LUMINANCE
||
3852 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3853 baseInternalFormat
== GL_INTENSITY
);
3854 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3856 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3857 * to integer formats.
3859 if (!srcPacking
->SwapBytes
&&
3860 baseInternalFormat
== srcFormat
&&
3861 srcType
== GL_UNSIGNED_SHORT
) {
3862 /* simple memcpy path */
3863 memcpy_texture(ctx
, dims
,
3864 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3865 dstRowStride
, dstSlices
,
3866 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3867 srcAddr
, srcPacking
);
3871 const GLuint
*tempImage
=
3872 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3873 srcWidth
, srcHeight
, srcDepth
,
3874 srcFormat
, srcType
, srcAddr
, srcPacking
);
3875 const GLuint
*src
= tempImage
;
3879 for (img
= 0; img
< srcDepth
; img
++) {
3880 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3881 + dstYoffset
* dstRowStride
3882 + dstXoffset
* texelBytes
;
3883 for (row
= 0; row
< srcHeight
; row
++) {
3884 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3886 for (i
= 0; i
< srcWidth
* components
; i
++) {
3887 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3889 dstRow
+= dstRowStride
;
3890 src
+= srcWidth
* components
;
3894 free((void *) tempImage
);
3900 /* non-normalized, unsigned int32 */
3902 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3904 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3905 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3906 const GLint components
= _mesa_components_in_format(baseFormat
);
3908 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3909 dstFormat
== MESA_FORMAT_RG_UINT32
||
3910 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3911 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3912 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3913 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3914 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3915 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3916 ASSERT(baseInternalFormat
== GL_RGBA
||
3917 baseInternalFormat
== GL_RGB
||
3918 baseInternalFormat
== GL_ALPHA
||
3919 baseInternalFormat
== GL_LUMINANCE
||
3920 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3921 baseInternalFormat
== GL_INTENSITY
);
3922 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3924 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3925 * to integer formats.
3927 if (!srcPacking
->SwapBytes
&&
3928 baseInternalFormat
== srcFormat
&&
3929 srcType
== GL_UNSIGNED_INT
) {
3930 /* simple memcpy path */
3931 memcpy_texture(ctx
, dims
,
3932 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3933 dstRowStride
, dstSlices
,
3934 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3935 srcAddr
, srcPacking
);
3939 const GLuint
*tempImage
=
3940 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3941 srcWidth
, srcHeight
, srcDepth
,
3942 srcFormat
, srcType
, srcAddr
, srcPacking
);
3943 const GLuint
*src
= tempImage
;
3947 for (img
= 0; img
< srcDepth
; img
++) {
3948 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3949 + dstYoffset
* dstRowStride
3950 + dstXoffset
* texelBytes
;
3951 for (row
= 0; row
< srcHeight
; row
++) {
3952 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3954 for (i
= 0; i
< srcWidth
* components
; i
++) {
3955 dstTexel
[i
] = src
[i
];
3957 dstRow
+= dstRowStride
;
3958 src
+= srcWidth
* components
;
3962 free((void *) tempImage
);
3970 #if FEATURE_EXT_texture_sRGB
3972 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3974 gl_format newDstFormat
;
3977 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3979 /* reuse normal rgb texstore code */
3980 newDstFormat
= MESA_FORMAT_RGB888
;
3982 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3984 dstXoffset
, dstYoffset
, dstZoffset
,
3985 dstRowStride
, dstSlices
,
3986 srcWidth
, srcHeight
, srcDepth
,
3988 srcAddr
, srcPacking
);
3994 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3996 gl_format newDstFormat
;
3999 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
4001 /* reuse normal rgba texstore code */
4002 newDstFormat
= MESA_FORMAT_RGBA8888
;
4003 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
4005 dstXoffset
, dstYoffset
, dstZoffset
,
4006 dstRowStride
, dstSlices
,
4007 srcWidth
, srcHeight
, srcDepth
,
4009 srcAddr
, srcPacking
);
4015 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
4017 gl_format newDstFormat
;
4020 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
4022 /* reuse normal rgba texstore code */
4023 newDstFormat
= MESA_FORMAT_ARGB8888
;
4025 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
4027 dstXoffset
, dstYoffset
, dstZoffset
,
4028 dstRowStride
, dstSlices
,
4029 srcWidth
, srcHeight
, srcDepth
,
4031 srcAddr
, srcPacking
);
4037 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
4039 gl_format newDstFormat
;
4042 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
4044 newDstFormat
= MESA_FORMAT_L8
;
4046 /* _mesa_textore_a8 handles luminance8 too */
4047 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
4049 dstXoffset
, dstYoffset
, dstZoffset
,
4050 dstRowStride
, dstSlices
,
4051 srcWidth
, srcHeight
, srcDepth
,
4053 srcAddr
, srcPacking
);
4059 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
4061 gl_format newDstFormat
;
4064 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4066 /* reuse normal luminance/alpha texstore code */
4067 newDstFormat
= MESA_FORMAT_AL88
;
4069 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4071 dstXoffset
, dstYoffset
, dstZoffset
,
4072 dstRowStride
, dstSlices
,
4073 srcWidth
, srcHeight
, srcDepth
,
4075 srcAddr
, srcPacking
);
4081 /* these are used only in texstore_funcs[] below */
4082 #define _mesa_texstore_srgb8 NULL
4083 #define _mesa_texstore_srgba8 NULL
4084 #define _mesa_texstore_sargb8 NULL
4085 #define _mesa_texstore_sl8 NULL
4086 #define _mesa_texstore_sla8 NULL
4088 #endif /* FEATURE_EXT_texture_sRGB */
4091 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
4093 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4095 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
4096 ASSERT(baseInternalFormat
== GL_RGB
);
4098 if (!ctx
->_ImageTransferState
&&
4099 !srcPacking
->SwapBytes
&&
4100 srcFormat
== GL_RGB
&&
4101 srcType
== GL_UNSIGNED_INT_5_9_9_9_REV
) {
4102 /* simple memcpy path */
4103 memcpy_texture(ctx
, dims
,
4104 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4105 dstRowStride
, dstSlices
,
4106 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4107 srcAddr
, srcPacking
);
4111 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4114 srcWidth
, srcHeight
, srcDepth
,
4115 srcFormat
, srcType
, srcAddr
,
4117 ctx
->_ImageTransferState
);
4118 const GLfloat
*srcRow
= tempImage
;
4119 GLint img
, row
, col
;
4122 for (img
= 0; img
< srcDepth
; img
++) {
4123 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
4124 + dstYoffset
* dstRowStride
4126 for (row
= 0; row
< srcHeight
; row
++) {
4127 GLuint
*dstUI
= (GLuint
*)dstRow
;
4128 for (col
= 0; col
< srcWidth
; col
++) {
4129 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
4131 dstRow
+= dstRowStride
;
4132 srcRow
+= srcWidth
* 3;
4136 free((void *) tempImage
);
4142 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
4144 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4146 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
4147 ASSERT(baseInternalFormat
== GL_RGB
);
4149 if (!ctx
->_ImageTransferState
&&
4150 !srcPacking
->SwapBytes
&&
4151 srcFormat
== GL_RGB
&&
4152 srcType
== GL_UNSIGNED_INT_10F_11F_11F_REV
) {
4153 /* simple memcpy path */
4154 memcpy_texture(ctx
, dims
,
4155 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4156 dstRowStride
, dstSlices
,
4157 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4158 srcAddr
, srcPacking
);
4162 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4165 srcWidth
, srcHeight
, srcDepth
,
4166 srcFormat
, srcType
, srcAddr
,
4168 ctx
->_ImageTransferState
);
4169 const GLfloat
*srcRow
= tempImage
;
4170 GLint img
, row
, col
;
4173 for (img
= 0; img
< srcDepth
; img
++) {
4174 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
4175 + dstYoffset
* dstRowStride
4177 for (row
= 0; row
< srcHeight
; row
++) {
4178 GLuint
*dstUI
= (GLuint
*)dstRow
;
4179 for (col
= 0; col
< srcWidth
; col
++) {
4180 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
4182 dstRow
+= dstRowStride
;
4183 srcRow
+= srcWidth
* 3;
4187 free((void *) tempImage
);
4194 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
4196 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
4197 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
4198 srcFormat
== GL_DEPTH_COMPONENT
||
4199 srcFormat
== GL_STENCIL_INDEX
);
4200 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
4201 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
4203 if (srcFormat
== GL_DEPTH_STENCIL
&&
4204 ctx
->Pixel
.DepthScale
== 1.0f
&&
4205 ctx
->Pixel
.DepthBias
== 0.0f
&&
4206 !srcPacking
->SwapBytes
) {
4208 memcpy_texture(ctx
, dims
,
4209 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4210 dstRowStride
, dstSlices
,
4211 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4212 srcAddr
, srcPacking
);
4214 else if (srcFormat
== GL_DEPTH_COMPONENT
||
4215 srcFormat
== GL_STENCIL_INDEX
) {
4217 const GLint srcRowStride
4218 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
4221 /* In case we only upload depth we need to preserve the stencil */
4222 for (img
= 0; img
< srcDepth
; img
++) {
4223 uint64_t *dstRow
= (uint64_t *) (dstSlices
[dstZoffset
+ img
]
4224 + dstYoffset
* dstRowStride
4227 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
4228 srcWidth
, srcHeight
,
4231 for (row
= 0; row
< srcHeight
; row
++) {
4232 /* The unpack functions with:
4233 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4234 * only write their own dword, so the other dword (stencil
4235 * or depth) is preserved. */
4236 if (srcFormat
!= GL_STENCIL_INDEX
)
4237 _mesa_unpack_depth_span(ctx
, srcWidth
,
4238 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4239 dstRow
, /* dst addr */
4240 1.0f
, srcType
, src
, srcPacking
);
4242 if (srcFormat
!= GL_DEPTH_COMPONENT
)
4243 _mesa_unpack_stencil_span(ctx
, srcWidth
,
4244 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4245 dstRow
, /* dst addr */
4246 srcType
, src
, srcPacking
,
4247 ctx
->_ImageTransferState
);
4249 src
+= srcRowStride
;
4250 dstRow
+= dstRowStride
/ sizeof(uint64_t);
4258 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
4260 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
4261 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4263 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
4264 ASSERT(texelBytes
== 4);
4266 if (!srcPacking
->SwapBytes
&&
4267 dstFormat
== MESA_FORMAT_ARGB2101010_UINT
&&
4268 srcFormat
== GL_BGRA_INTEGER_EXT
&&
4269 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
4270 baseInternalFormat
== GL_RGBA
) {
4271 /* simple memcpy path */
4272 memcpy_texture(ctx
, dims
,
4273 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4274 dstRowStride
, dstSlices
,
4275 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4276 srcAddr
, srcPacking
);
4280 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
4283 srcWidth
, srcHeight
,
4284 srcDepth
, srcFormat
,
4287 const GLuint
*src
= tempImage
;
4288 GLint img
, row
, col
;
4291 for (img
= 0; img
< srcDepth
; img
++) {
4292 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
4293 + dstYoffset
* dstRowStride
4294 + dstXoffset
* texelBytes
;
4296 for (row
= 0; row
< srcHeight
; row
++) {
4297 GLuint
*dstUI
= (GLuint
*) dstRow
;
4298 for (col
= 0; col
< srcWidth
; col
++) {
4304 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
4307 dstRow
+= dstRowStride
;
4310 free((void *) tempImage
);
4316 _mesa_texstore_null(TEXSTORE_PARAMS
)
4318 (void) ctx
; (void) dims
;
4319 (void) baseInternalFormat
;
4321 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4322 (void) dstRowStride
; (void) dstSlices
,
4323 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4324 (void) srcFormat
; (void) srcType
;
4328 /* should never happen */
4329 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4335 * Return the StoreTexImageFunc pointer to store an image in the given format.
4337 static StoreTexImageFunc
4338 _mesa_get_texstore_func(gl_format format
)
4340 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
4341 static GLboolean initialized
= GL_FALSE
;
4344 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
4346 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
4347 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
4348 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
4349 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
4350 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
4351 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
4352 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
4353 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
4354 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
4355 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
4356 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
4357 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
4358 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
4359 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
4360 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
4361 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
4362 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
4363 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
4364 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
4365 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
4366 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
4367 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
4368 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
4369 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
4370 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
4371 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
4372 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
4373 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
4374 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
4375 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
4376 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
4377 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
4378 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
4379 table
[MESA_FORMAT_RG88_REV
] = _mesa_texstore_unorm88
;
4380 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
4381 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
4382 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
4383 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
4384 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
4385 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
4386 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
4387 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
4388 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
4389 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
4390 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
4391 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
4392 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
4393 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
4394 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
4395 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
4396 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4397 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4398 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4399 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4400 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
4401 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
4402 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4403 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4404 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4405 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4406 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4407 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4408 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
4409 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
4410 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4411 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4412 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
4413 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
4414 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4415 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4416 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
4417 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
4418 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
4419 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
4420 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
4421 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
4422 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
4423 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
4424 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
4425 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
4426 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
4427 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
4428 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
4429 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
4430 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
4431 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
4432 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
4433 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
4434 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
4435 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
4436 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
4437 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
4438 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
4439 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
4440 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
4441 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
4442 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
4443 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
4444 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
4445 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
4446 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
4447 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
4448 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
4449 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
4450 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
4451 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
4452 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
4453 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
4455 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4456 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4457 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4458 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4459 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4460 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4462 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
4463 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
4464 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
4465 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
4466 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
4467 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
4469 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
4470 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
4471 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
4472 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
4473 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
4474 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4476 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4477 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4478 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4479 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4480 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4481 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4483 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4484 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4485 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4486 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4487 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4488 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4489 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4490 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4491 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4492 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4493 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4494 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4496 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4497 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4498 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4499 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4500 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4501 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4502 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4503 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4504 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4505 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4506 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4507 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4509 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
4510 initialized
= GL_TRUE
;
4513 ASSERT(table
[format
]);
4514 return table
[format
];
4519 * Store user data into texture memory.
4520 * Called via glTex[Sub]Image1/2/3D()
4523 _mesa_texstore(TEXSTORE_PARAMS
)
4525 StoreTexImageFunc storeImage
;
4528 storeImage
= _mesa_get_texstore_func(dstFormat
);
4530 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4531 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4532 dstRowStride
, dstSlices
,
4533 srcWidth
, srcHeight
, srcDepth
,
4534 srcFormat
, srcType
, srcAddr
, srcPacking
);
4540 * Normally, we'll only _write_ texel data to a texture when we map it.
4541 * But if the user is providing depth or stencil values and the texture
4542 * image is a combined depth/stencil format, we'll actually read from
4543 * the texture buffer too (in order to insert the depth or stencil values.
4544 * \param userFormat the user-provided image format
4545 * \param texFormat the destination texture format
4548 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4550 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4551 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4552 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4554 return GL_MAP_WRITE_BIT
;
4558 * This is the software fallback for Driver.TexImage1D().
4559 * \sa _mesa_store_teximage2d()
4562 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4563 GLint internalFormat
,
4564 GLint width
, GLint border
,
4565 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4566 const struct gl_pixelstore_attrib
*packing
,
4567 struct gl_texture_object
*texObj
,
4568 struct gl_texture_image
*texImage
)
4570 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4580 /* allocate storage for texture data */
4581 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4583 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4587 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4588 pixels
, packing
, "glTexImage1D");
4590 /* Note: we check for a NULL image pointer here, _after_ we allocated
4591 * memory for the texture. That's what the GL spec calls for.
4596 /* Map dest texture buffer (write to whole region) */
4597 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4600 &dstMap
, &dstRowStride
);
4602 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4603 texImage
->TexFormat
,
4604 0, 0, 0, /* dstX/Y/Zoffset */
4605 0, /* dstRowStride */
4608 format
, type
, pixels
, packing
);
4610 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4617 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4619 _mesa_unmap_teximage_pbo(ctx
, packing
);
4624 * This is the software fallback for Driver.TexImage2D().
4626 * This function is oriented toward storing images in main memory, rather
4627 * than VRAM. Device driver's can easily plug in their own replacement.
4630 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4631 GLint internalFormat
,
4632 GLint width
, GLint height
, GLint border
,
4633 GLenum format
, GLenum type
, const void *pixels
,
4634 const struct gl_pixelstore_attrib
*packing
,
4635 struct gl_texture_object
*texObj
,
4636 struct gl_texture_image
*texImage
)
4638 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4645 if (width
== 0 || height
== 0)
4648 /* allocate storage for texture data */
4649 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4650 width
, height
, 1)) {
4651 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4655 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4656 pixels
, packing
, "glTexImage2D");
4658 /* Note: we check for a NULL image pointer here, _after_ we allocated
4659 * memory for the texture. That's what the GL spec calls for.
4664 if (target
== GL_TEXTURE_1D_ARRAY
) {
4665 const GLint srcStride
=
4666 _mesa_image_row_stride(packing
, width
, format
, type
);
4671 for (y
= 0; y
< height
; y
++) {
4672 /* Map dest texture buffer (write to whole region) */
4673 ctx
->Driver
.MapTextureImage(ctx
, texImage
, y
,
4676 &dstMap
, &dstRowStride
);
4678 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4679 texImage
->TexFormat
,
4680 0, 0, 0, /* dstX/Y/Zoffset */
4684 format
, type
, pixels
, packing
);
4685 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, y
);
4694 pixels
= (const GLubyte
*) pixels
+ srcStride
;
4697 /* Map dest texture buffer (write to whole region) */
4698 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4699 0, 0, width
, height
,
4701 &dstMap
, &dstRowStride
);
4703 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4704 texImage
->TexFormat
,
4705 0, 0, 0, /* dstX/Y/Zoffset */
4709 format
, type
, pixels
, packing
);
4711 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4719 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4721 _mesa_unmap_teximage_pbo(ctx
, packing
);
4727 * This is the software fallback for Driver.TexImage3D().
4728 * \sa _mesa_store_teximage2d()
4731 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4732 GLint internalFormat
,
4733 GLint width
, GLint height
, GLint depth
, GLint border
,
4734 GLenum format
, GLenum type
, const void *pixels
,
4735 const struct gl_pixelstore_attrib
*packing
,
4736 struct gl_texture_object
*texObj
,
4737 struct gl_texture_image
*texImage
)
4739 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4740 GLboolean success
= GL_TRUE
;
4742 GLubyte
**sliceMaps
;
4747 if (width
== 0 || height
== 0 || depth
== 0)
4750 /* allocate storage for texture data */
4751 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4752 width
, height
, depth
)) {
4753 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4757 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
,
4759 pixels
, packing
, "glTexImage3D");
4761 /* Note: we check for a NULL image pointer here, _after_ we allocated
4762 * memory for the texture. That's what the GL spec calls for.
4767 if (target
== GL_TEXTURE_1D_ARRAY
) {
4772 sliceMaps
= (GLubyte
**) calloc(depth
, sizeof(GLubyte
*));
4774 /* Map dest texture buffer slices */
4775 for (slice
= 0; slice
< depth
; slice
++) {
4776 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
,
4777 0, 0, width
, height
,
4779 &sliceMaps
[slice
], &dstRowStride
);
4780 if (!sliceMaps
[slice
]) {
4787 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4788 texImage
->TexFormat
,
4789 0, 0, 0, /* dstX/Y/Zoffset */
4792 width
, height
, depth
,
4793 format
, type
, pixels
, packing
);
4796 /* Unmap dest texture buffer slices */
4797 for (slice
= 0; slice
< depth
; slice
++) {
4798 if (sliceMaps
[slice
]) {
4799 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
);
4804 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4806 _mesa_unmap_teximage_pbo(ctx
, packing
);
4815 * This is the software fallback for Driver.TexSubImage1D()
4816 * and Driver.CopyTexSubImage1D().
4819 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4820 GLint xoffset
, GLint width
,
4821 GLenum format
, GLenum type
, const void *pixels
,
4822 const struct gl_pixelstore_attrib
*packing
,
4823 struct gl_texture_object
*texObj
,
4824 struct gl_texture_image
*texImage
)
4826 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4831 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4832 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4833 pixels
, packing
, "glTexSubImage1D");
4837 /* Map dest texture buffer (write to whole region) */
4838 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4839 xoffset
, 0, width
, 1,
4841 &dstMap
, &dstRowStride
);
4844 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4845 texImage
->TexFormat
,
4846 0, 0, 0, /* dstX/Y/Zoffset */
4850 format
, type
, pixels
, packing
);
4852 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4859 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4861 _mesa_unmap_teximage_pbo(ctx
, packing
);
4867 * This is the software fallback for Driver.TexSubImage2D()
4868 * and Driver.CopyTexSubImage2D().
4871 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4872 GLint xoffset
, GLint yoffset
,
4873 GLint width
, GLint height
,
4874 GLenum format
, GLenum type
, const void *pixels
,
4875 const struct gl_pixelstore_attrib
*packing
,
4876 struct gl_texture_object
*texObj
,
4877 struct gl_texture_image
*texImage
)
4879 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4884 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4885 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4886 pixels
, packing
, "glTexSubImage2D");
4890 /* Map dest texture buffer (write to whole region) */
4891 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4892 xoffset
, yoffset
, width
, height
,
4894 &dstMap
, &dstRowStride
);
4897 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4898 texImage
->TexFormat
,
4899 0, 0, 0, /* dstX/Y/Zoffset */
4903 format
, type
, pixels
, packing
);
4905 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4912 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4914 _mesa_unmap_teximage_pbo(ctx
, packing
);
4919 * This is the software fallback for Driver.TexSubImage3D().
4920 * and Driver.CopyTexSubImage3D().
4923 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4924 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4925 GLint width
, GLint height
, GLint depth
,
4926 GLenum format
, GLenum type
, const void *pixels
,
4927 const struct gl_pixelstore_attrib
*packing
,
4928 struct gl_texture_object
*texObj
,
4929 struct gl_texture_image
*texImage
)
4931 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4932 GLboolean success
= GL_TRUE
;
4934 GLubyte
**sliceMaps
;
4937 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4938 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4939 type
, pixels
, packing
,
4944 sliceMaps
= (GLubyte
**) calloc(depth
, sizeof(GLubyte
*));
4946 /* Map dest texture buffer slices */
4947 for (slice
= 0; slice
< depth
; slice
++) {
4948 ctx
->Driver
.MapTextureImage(ctx
, texImage
, zoffset
+ slice
,
4949 xoffset
, yoffset
, width
, height
,
4951 &sliceMaps
[slice
], &dstRowStride
);
4952 if (!sliceMaps
[slice
]) {
4959 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4960 texImage
->TexFormat
,
4964 width
, height
, depth
,
4965 format
, type
, pixels
, packing
);
4968 /* Unmap dest texture buffer slices */
4969 for (slice
= 0; slice
< depth
; slice
++) {
4970 if (sliceMaps
[slice
]) {
4971 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, zoffset
+ slice
);
4976 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4978 _mesa_unmap_teximage_pbo(ctx
, packing
);
4985 * Fallback for Driver.CompressedTexImage1D()
4988 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4989 GLenum target
, GLint level
,
4990 GLint internalFormat
,
4991 GLint width
, GLint border
,
4992 GLsizei imageSize
, const GLvoid
*data
,
4993 struct gl_texture_object
*texObj
,
4994 struct gl_texture_image
*texImage
)
4996 /* this space intentionally left blank */
4998 (void) target
; (void) level
;
4999 (void) internalFormat
;
5000 (void) width
; (void) border
;
5001 (void) imageSize
; (void) data
;
5009 * Fallback for Driver.CompressedTexImage2D()
5012 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
5013 GLenum target
, GLint level
,
5014 GLint internalFormat
,
5015 GLint width
, GLint height
, GLint border
,
5016 GLsizei imageSize
, const GLvoid
*data
,
5017 struct gl_texture_object
*texObj
,
5018 struct gl_texture_image
*texImage
)
5023 /* This is pretty simple, basically just do a memcpy without worrying
5024 * about the usual image unpacking or image transfer operations.
5028 ASSERT(texImage
->Width
> 0);
5029 ASSERT(texImage
->Height
> 0);
5030 ASSERT(texImage
->Depth
== 1);
5032 /* allocate storage for texture data */
5033 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
5034 width
, height
, 1)) {
5035 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
5039 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
5041 "glCompressedTexImage2D");
5046 /* Map dest texture buffer (write to whole region) */
5047 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
5048 0, 0, width
, height
,
5050 &dstMap
, &dstRowStride
);
5053 memcpy(dstMap
, data
, imageSize
);
5055 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
5058 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
5061 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
5067 * Fallback for Driver.CompressedTexImage3D()
5070 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
5071 GLenum target
, GLint level
,
5072 GLint internalFormat
,
5073 GLint width
, GLint height
, GLint depth
,
5075 GLsizei imageSize
, const GLvoid
*data
,
5076 struct gl_texture_object
*texObj
,
5077 struct gl_texture_image
*texImage
)
5079 /* this space intentionally left blank */
5081 (void) target
; (void) level
;
5082 (void) internalFormat
;
5083 (void) width
; (void) height
; (void) depth
;
5085 (void) imageSize
; (void) data
;
5093 * Fallback for Driver.CompressedTexSubImage1D()
5096 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
5098 GLint xoffset
, GLsizei width
,
5100 GLsizei imageSize
, const GLvoid
*data
,
5101 struct gl_texture_object
*texObj
,
5102 struct gl_texture_image
*texImage
)
5104 /* there are no compressed 1D texture formats yet */
5106 (void) target
; (void) level
;
5107 (void) xoffset
; (void) width
;
5109 (void) imageSize
; (void) data
;
5116 * Fallback for Driver.CompressedTexSubImage2D()
5119 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
5121 GLint xoffset
, GLint yoffset
,
5122 GLsizei width
, GLsizei height
,
5124 GLsizei imageSize
, const GLvoid
*data
,
5125 struct gl_texture_object
*texObj
,
5126 struct gl_texture_image
*texImage
)
5128 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
5132 const gl_format texFormat
= texImage
->TexFormat
;
5135 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
5137 /* these should have been caught sooner */
5138 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
5139 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
5140 ASSERT((xoffset
% bw
) == 0);
5141 ASSERT((yoffset
% bh
) == 0);
5143 /* get pointer to src pixels (may be in a pbo which we'll map here) */
5144 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
5146 "glCompressedTexSubImage2D");
5150 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
5151 src
= (const GLubyte
*) data
;
5153 /* Map dest texture buffer (write to whole region) */
5154 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
5155 xoffset
, yoffset
, width
, height
,
5157 &dstMap
, &dstRowStride
);
5160 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
5161 rows
= height
/ bh
; /* rows in blocks */
5163 /* copy rows of blocks */
5164 for (i
= 0; i
< rows
; i
++) {
5165 memcpy(dstMap
, src
, bytesPerRow
);
5166 dstMap
+= dstRowStride
;
5167 src
+= srcRowStride
;
5170 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
5173 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage2D");
5176 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
5181 * Fallback for Driver.CompressedTexSubImage3D()
5184 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
5186 GLint xoffset
, GLint yoffset
, GLint zoffset
,
5187 GLsizei width
, GLsizei height
, GLsizei depth
,
5189 GLsizei imageSize
, const GLvoid
*data
,
5190 struct gl_texture_object
*texObj
,
5191 struct gl_texture_image
*texImage
)
5193 /* there are no compressed 3D texture formats yet */
5195 (void) target
; (void) level
;
5196 (void) xoffset
; (void) yoffset
; (void) zoffset
;
5197 (void) width
; (void) height
; (void) depth
;
5199 (void) imageSize
; (void) data
;