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
,
857 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
858 const GLvoid
*srcAddr
,
859 const struct gl_pixelstore_attrib
*srcPacking
)
861 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
862 const GLubyte
*srctype2ubyte
, *swap
;
863 GLubyte map
[4], src2base
[6], base2rgba
[6];
865 const GLint srcRowStride
=
866 _mesa_image_row_stride(srcPacking
, srcWidth
,
867 srcFormat
, GL_UNSIGNED_BYTE
);
868 const GLint srcImageStride
869 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
871 const GLubyte
*srcImage
872 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
873 srcWidth
, srcHeight
, srcFormat
,
874 GL_UNSIGNED_BYTE
, 0, 0, 0);
878 /* Translate from src->baseInternal->GL_RGBA->dst. This will
879 * correctly deal with RGBA->RGB->RGBA conversions where the final
880 * A value must be 0xff regardless of the incoming alpha values.
882 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
883 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
884 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
885 srctype2ubyte
= type_mapping(srcType
);
888 for (i
= 0; i
< 4; i
++)
889 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
891 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
893 if (srcComponents
== dstComponents
&&
894 srcRowStride
== dstRowStride
&&
895 srcRowStride
== srcWidth
* srcComponents
&&
897 /* 1 and 2D images only */
898 GLubyte
*dstImage
= dstSlices
[0];
899 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
900 srcWidth
* srcHeight
);
904 for (img
= 0; img
< srcDepth
; img
++) {
905 const GLubyte
*srcRow
= srcImage
;
906 GLubyte
*dstRow
= dstSlices
[img
];
907 for (row
= 0; row
< srcHeight
; row
++) {
908 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
909 dstRow
+= dstRowStride
;
910 srcRow
+= srcRowStride
;
912 srcImage
+= srcImageStride
;
919 * Teximage storage routine for when a simple memcpy will do.
920 * No pixel transfer operations or special texel encodings allowed.
921 * 1D, 2D and 3D images supported.
924 memcpy_texture(struct gl_context
*ctx
,
929 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
930 GLenum srcFormat
, GLenum srcType
,
931 const GLvoid
*srcAddr
,
932 const struct gl_pixelstore_attrib
*srcPacking
)
934 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
936 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
937 srcWidth
, srcHeight
, srcFormat
, srcType
);
938 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
939 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
940 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
941 const GLint bytesPerRow
= srcWidth
* texelBytes
;
943 if (dstRowStride
== srcRowStride
&&
944 dstRowStride
== bytesPerRow
) {
945 /* memcpy image by image */
947 for (img
= 0; img
< srcDepth
; img
++) {
948 GLubyte
*dstImage
= dstSlices
[img
];
949 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
950 srcImage
+= srcImageStride
;
954 /* memcpy row by row */
956 for (img
= 0; img
< srcDepth
; img
++) {
957 const GLubyte
*srcRow
= srcImage
;
958 GLubyte
*dstRow
= dstSlices
[img
];
959 for (row
= 0; row
< srcHeight
; row
++) {
960 memcpy(dstRow
, srcRow
, bytesPerRow
);
961 dstRow
+= dstRowStride
;
962 srcRow
+= srcRowStride
;
964 srcImage
+= srcImageStride
;
972 * Store a 32-bit integer or float depth component texture image.
975 _mesa_texstore_z32(TEXSTORE_PARAMS
)
977 const GLuint depthScale
= 0xffffffff;
980 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
981 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
982 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
984 if (dstFormat
== MESA_FORMAT_Z32
)
985 dstType
= GL_UNSIGNED_INT
;
989 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
990 ctx
->Pixel
.DepthBias
== 0.0f
&&
991 !srcPacking
->SwapBytes
&&
992 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
993 srcFormat
== GL_DEPTH_COMPONENT
&&
994 srcType
== dstType
) {
995 /* simple memcpy path */
996 memcpy_texture(ctx
, dims
,
998 dstRowStride
, dstSlices
,
999 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1000 srcAddr
, srcPacking
);
1005 for (img
= 0; img
< srcDepth
; img
++) {
1006 GLubyte
*dstRow
= dstSlices
[img
];
1007 for (row
= 0; row
< srcHeight
; row
++) {
1008 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1009 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1010 _mesa_unpack_depth_span(ctx
, srcWidth
,
1012 depthScale
, srcType
, src
, srcPacking
);
1013 dstRow
+= dstRowStride
;
1022 * Store a 24-bit integer depth component texture image.
1025 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1027 const GLuint depthScale
= 0xffffff;
1030 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1035 for (img
= 0; img
< srcDepth
; img
++) {
1036 GLubyte
*dstRow
= dstSlices
[img
];
1037 for (row
= 0; row
< srcHeight
; row
++) {
1038 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1039 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1040 _mesa_unpack_depth_span(ctx
, srcWidth
,
1041 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1042 depthScale
, srcType
, src
, srcPacking
);
1043 dstRow
+= dstRowStride
;
1052 * Store a 24-bit integer depth component texture image.
1055 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1057 const GLuint depthScale
= 0xffffff;
1060 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1065 for (img
= 0; img
< srcDepth
; img
++) {
1066 GLubyte
*dstRow
= dstSlices
[img
];
1067 for (row
= 0; row
< srcHeight
; row
++) {
1068 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1069 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1070 GLuint
*dst
= (GLuint
*) dstRow
;
1072 _mesa_unpack_depth_span(ctx
, srcWidth
,
1073 GL_UNSIGNED_INT
, dst
,
1074 depthScale
, srcType
, src
, srcPacking
);
1075 for (i
= 0; i
< srcWidth
; i
++)
1077 dstRow
+= dstRowStride
;
1086 * Store a 16-bit integer depth component texture image.
1089 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1091 const GLuint depthScale
= 0xffff;
1093 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1094 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1096 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1097 ctx
->Pixel
.DepthBias
== 0.0f
&&
1098 !srcPacking
->SwapBytes
&&
1099 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1100 srcFormat
== GL_DEPTH_COMPONENT
&&
1101 srcType
== GL_UNSIGNED_SHORT
) {
1102 /* simple memcpy path */
1103 memcpy_texture(ctx
, dims
,
1105 dstRowStride
, dstSlices
,
1106 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1107 srcAddr
, srcPacking
);
1112 for (img
= 0; img
< srcDepth
; img
++) {
1113 GLubyte
*dstRow
= dstSlices
[img
];
1114 for (row
= 0; row
< srcHeight
; row
++) {
1115 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1116 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1117 GLushort
*dst16
= (GLushort
*) dstRow
;
1118 _mesa_unpack_depth_span(ctx
, srcWidth
,
1119 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1120 srcType
, src
, srcPacking
);
1121 dstRow
+= dstRowStride
;
1130 * Store an rgb565 or rgb565_rev texture image.
1133 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1135 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1137 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1138 dstFormat
== MESA_FORMAT_RGB565_REV
);
1139 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1141 if (!ctx
->_ImageTransferState
&&
1142 !srcPacking
->SwapBytes
&&
1143 dstFormat
== MESA_FORMAT_RGB565
&&
1144 baseInternalFormat
== GL_RGB
&&
1145 srcFormat
== GL_RGB
&&
1146 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1147 /* simple memcpy path */
1148 memcpy_texture(ctx
, dims
,
1150 dstRowStride
, dstSlices
,
1151 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1152 srcAddr
, srcPacking
);
1154 else if (!ctx
->_ImageTransferState
&&
1155 !srcPacking
->SwapBytes
&&
1156 baseInternalFormat
== GL_RGB
&&
1157 srcFormat
== GL_RGB
&&
1158 srcType
== GL_UNSIGNED_BYTE
&&
1160 /* do optimized tex store */
1161 const GLint srcRowStride
=
1162 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1163 const GLubyte
*src
= (const GLubyte
*)
1164 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1165 srcFormat
, srcType
, 0, 0, 0);
1166 GLubyte
*dst
= dstSlices
[0];
1168 for (row
= 0; row
< srcHeight
; row
++) {
1169 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1170 GLushort
*dstUS
= (GLushort
*) dst
;
1171 /* check for byteswapped format */
1172 if (dstFormat
== MESA_FORMAT_RGB565
) {
1173 for (col
= 0; col
< srcWidth
; col
++) {
1174 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1179 for (col
= 0; col
< srcWidth
; col
++) {
1180 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1184 dst
+= dstRowStride
;
1185 src
+= srcRowStride
;
1190 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1193 srcWidth
, srcHeight
, srcDepth
,
1194 srcFormat
, srcType
, srcAddr
,
1196 const GLubyte
*src
= tempImage
;
1197 GLint img
, row
, col
;
1200 for (img
= 0; img
< srcDepth
; img
++) {
1201 GLubyte
*dstRow
= dstSlices
[img
];
1202 for (row
= 0; row
< srcHeight
; row
++) {
1203 GLushort
*dstUS
= (GLushort
*) dstRow
;
1204 /* check for byteswapped format */
1205 if (dstFormat
== MESA_FORMAT_RGB565
) {
1206 for (col
= 0; col
< srcWidth
; col
++) {
1207 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1214 for (col
= 0; col
< srcWidth
; col
++) {
1215 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1221 dstRow
+= dstRowStride
;
1224 free((void *) tempImage
);
1231 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1234 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1236 const GLboolean littleEndian
= _mesa_little_endian();
1237 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1239 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1240 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1241 dstFormat
== MESA_FORMAT_RGBX8888
||
1242 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1243 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1245 if (!ctx
->_ImageTransferState
&&
1246 !srcPacking
->SwapBytes
&&
1247 (dstFormat
== MESA_FORMAT_RGBA8888
||
1248 dstFormat
== MESA_FORMAT_RGBX8888
) &&
1249 baseInternalFormat
== GL_RGBA
&&
1250 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1251 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1252 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1253 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1254 /* simple memcpy path */
1255 memcpy_texture(ctx
, dims
,
1257 dstRowStride
, dstSlices
,
1258 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1259 srcAddr
, srcPacking
);
1261 else if (!ctx
->_ImageTransferState
&&
1262 !srcPacking
->SwapBytes
&&
1263 (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1264 dstFormat
== MESA_FORMAT_RGBX8888_REV
) &&
1265 baseInternalFormat
== GL_RGBA
&&
1266 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1267 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1268 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1269 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1270 /* simple memcpy path */
1271 memcpy_texture(ctx
, dims
,
1273 dstRowStride
, dstSlices
,
1274 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1275 srcAddr
, srcPacking
);
1277 else if (!ctx
->_ImageTransferState
&&
1278 (srcType
== GL_UNSIGNED_BYTE
||
1279 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1280 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1281 can_swizzle(baseInternalFormat
) &&
1282 can_swizzle(srcFormat
)) {
1286 /* dstmap - how to swizzle from RGBA to dst format:
1288 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1289 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1290 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1291 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1304 _mesa_swizzle_ubyte_image(ctx
, dims
,
1309 dstRowStride
, dstSlices
,
1310 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1315 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1318 srcWidth
, srcHeight
, srcDepth
,
1319 srcFormat
, srcType
, srcAddr
,
1321 const GLubyte
*src
= tempImage
;
1322 GLint img
, row
, col
;
1325 for (img
= 0; img
< srcDepth
; img
++) {
1326 GLubyte
*dstRow
= dstSlices
[img
];
1327 for (row
= 0; row
< srcHeight
; row
++) {
1328 GLuint
*dstUI
= (GLuint
*) dstRow
;
1329 if (dstFormat
== MESA_FORMAT_RGBA8888
||
1330 dstFormat
== MESA_FORMAT_RGBX8888
) {
1331 for (col
= 0; col
< srcWidth
; col
++) {
1332 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1340 for (col
= 0; col
< srcWidth
; col
++) {
1341 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1348 dstRow
+= dstRowStride
;
1351 free((void *) tempImage
);
1358 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1360 const GLboolean littleEndian
= _mesa_little_endian();
1361 const GLenum baseFormat
= GL_RGBA
;
1363 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1364 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1365 dstFormat
== MESA_FORMAT_XRGB8888
||
1366 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1367 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1369 if (!ctx
->_ImageTransferState
&&
1370 !srcPacking
->SwapBytes
&&
1371 (dstFormat
== MESA_FORMAT_ARGB8888
||
1372 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1373 baseInternalFormat
== GL_RGBA
&&
1374 srcFormat
== GL_BGRA
&&
1375 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1376 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1377 /* simple memcpy path (little endian) */
1378 memcpy_texture(ctx
, dims
,
1380 dstRowStride
, dstSlices
,
1381 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1382 srcAddr
, srcPacking
);
1384 else if (!ctx
->_ImageTransferState
&&
1385 !srcPacking
->SwapBytes
&&
1386 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1387 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1388 baseInternalFormat
== GL_RGBA
&&
1389 srcFormat
== GL_BGRA
&&
1390 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1391 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1392 /* simple memcpy path (big endian) */
1393 memcpy_texture(ctx
, dims
,
1395 dstRowStride
, dstSlices
,
1396 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1397 srcAddr
, srcPacking
);
1399 else if (!ctx
->_ImageTransferState
&&
1400 !srcPacking
->SwapBytes
&&
1401 (dstFormat
== MESA_FORMAT_ARGB8888
||
1402 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1403 srcFormat
== GL_RGB
&&
1404 (baseInternalFormat
== GL_RGBA
||
1405 baseInternalFormat
== GL_RGB
) &&
1406 srcType
== GL_UNSIGNED_BYTE
) {
1408 for (img
= 0; img
< srcDepth
; img
++) {
1409 const GLint srcRowStride
=
1410 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1411 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1412 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1413 GLubyte
*dstRow
= dstSlices
[img
];
1414 for (row
= 0; row
< srcHeight
; row
++) {
1415 GLuint
*d4
= (GLuint
*) dstRow
;
1416 for (col
= 0; col
< srcWidth
; col
++) {
1417 d4
[col
] = PACK_COLOR_8888(0xff,
1418 srcRow
[col
* 3 + RCOMP
],
1419 srcRow
[col
* 3 + GCOMP
],
1420 srcRow
[col
* 3 + BCOMP
]);
1422 dstRow
+= dstRowStride
;
1423 srcRow
+= srcRowStride
;
1427 else if (!ctx
->_ImageTransferState
&&
1428 !srcPacking
->SwapBytes
&&
1429 dstFormat
== MESA_FORMAT_ARGB8888
&&
1430 srcFormat
== GL_RGBA
&&
1431 baseInternalFormat
== GL_RGBA
&&
1432 srcType
== GL_UNSIGNED_BYTE
) {
1433 /* same as above case, but src data has alpha too */
1434 GLint img
, row
, col
;
1435 /* For some reason, streaming copies to write-combined regions
1436 * are extremely sensitive to the characteristics of how the
1437 * source data is retrieved. By reordering the source reads to
1438 * be in-order, the speed of this operation increases by half.
1439 * Strangely the same isn't required for the RGB path, above.
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
[img
];
1447 for (row
= 0; row
< srcHeight
; row
++) {
1448 GLuint
*d4
= (GLuint
*) dstRow
;
1449 for (col
= 0; col
< srcWidth
; col
++) {
1450 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1451 srcRow
[col
* 4 + RCOMP
],
1452 srcRow
[col
* 4 + GCOMP
],
1453 srcRow
[col
* 4 + BCOMP
]);
1455 dstRow
+= dstRowStride
;
1456 srcRow
+= srcRowStride
;
1460 else if (!ctx
->_ImageTransferState
&&
1461 (srcType
== GL_UNSIGNED_BYTE
||
1462 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1463 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1464 can_swizzle(baseInternalFormat
) &&
1465 can_swizzle(srcFormat
)) {
1469 /* dstmap - how to swizzle from RGBA to dst format:
1471 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1472 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1473 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1474 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1475 dstmap
[3] = 3; /* alpha */
1476 dstmap
[2] = 0; /* red */
1477 dstmap
[1] = 1; /* green */
1478 dstmap
[0] = 2; /* blue */
1481 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1482 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1483 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1484 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1491 _mesa_swizzle_ubyte_image(ctx
, dims
,
1498 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1503 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1506 srcWidth
, srcHeight
, srcDepth
,
1507 srcFormat
, srcType
, srcAddr
,
1509 const GLubyte
*src
= tempImage
;
1510 GLint img
, row
, col
;
1513 for (img
= 0; img
< srcDepth
; img
++) {
1514 GLubyte
*dstRow
= dstSlices
[img
];
1515 for (row
= 0; row
< srcHeight
; row
++) {
1516 GLuint
*dstUI
= (GLuint
*) dstRow
;
1517 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1518 for (col
= 0; col
< srcWidth
; col
++) {
1519 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1526 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1527 for (col
= 0; col
< srcWidth
; col
++) {
1528 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1536 for (col
= 0; col
< srcWidth
; col
++) {
1537 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1544 dstRow
+= dstRowStride
;
1547 free((void *) tempImage
);
1554 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1556 const GLboolean littleEndian
= _mesa_little_endian();
1557 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1559 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1560 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1562 if (!ctx
->_ImageTransferState
&&
1563 !srcPacking
->SwapBytes
&&
1564 baseInternalFormat
== GL_RGB
&&
1565 srcFormat
== GL_BGR
&&
1566 srcType
== GL_UNSIGNED_BYTE
&&
1568 /* simple memcpy path */
1569 memcpy_texture(ctx
, dims
,
1571 dstRowStride
, dstSlices
,
1572 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1573 srcAddr
, srcPacking
);
1575 else if (!ctx
->_ImageTransferState
&&
1576 !srcPacking
->SwapBytes
&&
1577 srcFormat
== GL_RGBA
&&
1578 srcType
== GL_UNSIGNED_BYTE
) {
1579 /* extract RGB from RGBA */
1580 GLint img
, row
, col
;
1581 for (img
= 0; img
< srcDepth
; img
++) {
1582 const GLint srcRowStride
=
1583 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1584 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1585 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1586 GLubyte
*dstRow
= dstSlices
[img
];
1587 for (row
= 0; row
< srcHeight
; row
++) {
1588 for (col
= 0; col
< srcWidth
; col
++) {
1589 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1590 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1591 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1593 dstRow
+= dstRowStride
;
1594 srcRow
+= srcRowStride
;
1598 else if (!ctx
->_ImageTransferState
&&
1599 srcType
== GL_UNSIGNED_BYTE
&&
1600 can_swizzle(baseInternalFormat
) &&
1601 can_swizzle(srcFormat
)) {
1605 /* dstmap - how to swizzle from RGBA to dst format:
1610 dstmap
[3] = ONE
; /* ? */
1612 _mesa_swizzle_ubyte_image(ctx
, dims
,
1617 dstRowStride
, dstSlices
,
1618 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1623 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1626 srcWidth
, srcHeight
, srcDepth
,
1627 srcFormat
, srcType
, srcAddr
,
1629 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1630 GLint img
, row
, col
;
1633 for (img
= 0; img
< srcDepth
; img
++) {
1634 GLubyte
*dstRow
= dstSlices
[img
];
1635 for (row
= 0; row
< srcHeight
; row
++) {
1638 for (col
= 0; col
< srcWidth
; col
++) {
1639 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1640 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1641 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1646 for (col
= 0; col
< srcWidth
; col
++) {
1647 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1648 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1649 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1654 for (col
= 0; col
< srcWidth
; col
++) {
1655 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1656 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1657 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1661 dstRow
+= dstRowStride
;
1664 free((void *) tempImage
);
1671 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1673 const GLboolean littleEndian
= _mesa_little_endian();
1674 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1676 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1677 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1679 if (!ctx
->_ImageTransferState
&&
1680 !srcPacking
->SwapBytes
&&
1681 baseInternalFormat
== GL_RGB
&&
1682 srcFormat
== GL_RGB
&&
1683 srcType
== GL_UNSIGNED_BYTE
&&
1685 /* simple memcpy path */
1686 memcpy_texture(ctx
, dims
,
1688 dstRowStride
, dstSlices
,
1689 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1690 srcAddr
, srcPacking
);
1692 else if (!ctx
->_ImageTransferState
&&
1693 !srcPacking
->SwapBytes
&&
1694 srcFormat
== GL_RGBA
&&
1695 srcType
== GL_UNSIGNED_BYTE
) {
1696 /* extract BGR from RGBA */
1698 for (img
= 0; img
< srcDepth
; img
++) {
1699 const GLint srcRowStride
=
1700 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1701 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1702 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1703 GLubyte
*dstRow
= dstSlices
[img
];
1704 for (row
= 0; row
< srcHeight
; row
++) {
1705 for (col
= 0; col
< srcWidth
; col
++) {
1706 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1707 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1708 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1710 dstRow
+= dstRowStride
;
1711 srcRow
+= srcRowStride
;
1715 else if (!ctx
->_ImageTransferState
&&
1716 srcType
== GL_UNSIGNED_BYTE
&&
1717 can_swizzle(baseInternalFormat
) &&
1718 can_swizzle(srcFormat
)) {
1722 /* dstmap - how to swizzle from RGBA to dst format:
1727 dstmap
[3] = ONE
; /* ? */
1729 _mesa_swizzle_ubyte_image(ctx
, dims
,
1734 dstRowStride
, dstSlices
,
1735 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1740 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1743 srcWidth
, srcHeight
, srcDepth
,
1744 srcFormat
, srcType
, srcAddr
,
1746 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1747 GLint img
, row
, col
;
1750 for (img
= 0; img
< srcDepth
; img
++) {
1751 GLubyte
*dstRow
= dstSlices
[img
];
1752 for (row
= 0; row
< srcHeight
; row
++) {
1753 for (col
= 0; col
< srcWidth
; col
++) {
1754 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1755 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1756 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1759 dstRow
+= dstRowStride
;
1762 free((void *) tempImage
);
1769 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1771 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1773 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1774 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1775 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1777 if (!ctx
->_ImageTransferState
&&
1778 !srcPacking
->SwapBytes
&&
1779 dstFormat
== MESA_FORMAT_ARGB4444
&&
1780 baseInternalFormat
== GL_RGBA
&&
1781 srcFormat
== GL_BGRA
&&
1782 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1783 /* simple memcpy path */
1784 memcpy_texture(ctx
, dims
,
1786 dstRowStride
, dstSlices
,
1787 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1788 srcAddr
, srcPacking
);
1792 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1795 srcWidth
, srcHeight
, srcDepth
,
1796 srcFormat
, srcType
, srcAddr
,
1798 const GLubyte
*src
= tempImage
;
1799 GLint img
, row
, col
;
1802 for (img
= 0; img
< srcDepth
; img
++) {
1803 GLubyte
*dstRow
= dstSlices
[img
];
1804 for (row
= 0; row
< srcHeight
; row
++) {
1805 GLushort
*dstUS
= (GLushort
*) dstRow
;
1806 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1807 for (col
= 0; col
< srcWidth
; col
++) {
1808 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1816 for (col
= 0; col
< srcWidth
; col
++) {
1817 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1824 dstRow
+= dstRowStride
;
1827 free((void *) tempImage
);
1833 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1835 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1837 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1838 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1840 if (!ctx
->_ImageTransferState
&&
1841 !srcPacking
->SwapBytes
&&
1842 dstFormat
== MESA_FORMAT_RGBA5551
&&
1843 baseInternalFormat
== GL_RGBA
&&
1844 srcFormat
== GL_RGBA
&&
1845 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1846 /* simple memcpy path */
1847 memcpy_texture(ctx
, dims
,
1849 dstRowStride
, dstSlices
,
1850 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1851 srcAddr
, srcPacking
);
1855 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1858 srcWidth
, srcHeight
, srcDepth
,
1859 srcFormat
, srcType
, srcAddr
,
1861 const GLubyte
*src
=tempImage
;
1862 GLint img
, row
, col
;
1865 for (img
= 0; img
< srcDepth
; img
++) {
1866 GLubyte
*dstRow
= dstSlices
[img
];
1867 for (row
= 0; row
< srcHeight
; row
++) {
1868 GLushort
*dstUS
= (GLushort
*) dstRow
;
1869 for (col
= 0; col
< srcWidth
; col
++) {
1870 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1876 dstRow
+= dstRowStride
;
1879 free((void *) tempImage
);
1885 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1887 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1889 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1890 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1891 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1893 if (!ctx
->_ImageTransferState
&&
1894 !srcPacking
->SwapBytes
&&
1895 dstFormat
== MESA_FORMAT_ARGB1555
&&
1896 baseInternalFormat
== GL_RGBA
&&
1897 srcFormat
== GL_BGRA
&&
1898 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1899 /* simple memcpy path */
1900 memcpy_texture(ctx
, dims
,
1902 dstRowStride
, dstSlices
,
1903 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1904 srcAddr
, srcPacking
);
1908 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1911 srcWidth
, srcHeight
, srcDepth
,
1912 srcFormat
, srcType
, srcAddr
,
1914 const GLubyte
*src
=tempImage
;
1915 GLint img
, row
, col
;
1918 for (img
= 0; img
< srcDepth
; img
++) {
1919 GLubyte
*dstRow
= dstSlices
[img
];
1920 for (row
= 0; row
< srcHeight
; row
++) {
1921 GLushort
*dstUS
= (GLushort
*) dstRow
;
1922 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1923 for (col
= 0; col
< srcWidth
; col
++) {
1924 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
1932 for (col
= 0; col
< srcWidth
; col
++) {
1933 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
1940 dstRow
+= dstRowStride
;
1943 free((void *) tempImage
);
1950 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1952 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1954 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
1955 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1957 if (!ctx
->_ImageTransferState
&&
1958 !srcPacking
->SwapBytes
&&
1959 dstFormat
== MESA_FORMAT_ARGB2101010
&&
1960 srcFormat
== GL_BGRA
&&
1961 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1962 baseInternalFormat
== GL_RGBA
) {
1963 /* simple memcpy path */
1964 memcpy_texture(ctx
, dims
,
1966 dstRowStride
, dstSlices
,
1967 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1968 srcAddr
, srcPacking
);
1972 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1975 srcWidth
, srcHeight
, srcDepth
,
1976 srcFormat
, srcType
, srcAddr
,
1978 ctx
->_ImageTransferState
);
1979 const GLfloat
*src
= tempImage
;
1980 GLint img
, row
, col
;
1983 for (img
= 0; img
< srcDepth
; img
++) {
1984 GLubyte
*dstRow
= dstSlices
[img
];
1985 if (baseInternalFormat
== GL_RGBA
) {
1986 for (row
= 0; row
< srcHeight
; row
++) {
1987 GLuint
*dstUI
= (GLuint
*) dstRow
;
1988 for (col
= 0; col
< srcWidth
; col
++) {
1991 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1992 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1993 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1994 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1995 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1998 dstRow
+= dstRowStride
;
2000 } else if (baseInternalFormat
== GL_RGB
) {
2001 for (row
= 0; row
< srcHeight
; row
++) {
2002 GLuint
*dstUI
= (GLuint
*) dstRow
;
2003 for (col
= 0; col
< srcWidth
; col
++) {
2006 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2007 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2008 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2009 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2012 dstRow
+= dstRowStride
;
2018 free((void *) tempImage
);
2025 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2028 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2030 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2032 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2033 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2037 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2040 srcWidth
, srcHeight
, srcDepth
,
2041 srcFormat
, srcType
, srcAddr
,
2043 const GLubyte
*src
= tempImage
;
2044 GLint img
, row
, col
;
2047 for (img
= 0; img
< srcDepth
; img
++) {
2048 GLubyte
*dstRow
= dstSlices
[img
];
2049 for (row
= 0; row
< srcHeight
; row
++) {
2050 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2051 for (col
= 0; col
< srcWidth
; col
++) {
2052 /* src[0] is luminance, src[1] is alpha */
2053 dstUS
[col
] = PACK_COLOR_44( src
[1],
2057 dstRow
+= dstRowStride
;
2060 free((void *) tempImage
);
2067 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2070 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2072 const GLboolean littleEndian
= _mesa_little_endian();
2073 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2075 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2076 dstFormat
== MESA_FORMAT_AL88_REV
||
2077 dstFormat
== MESA_FORMAT_GR88
||
2078 dstFormat
== MESA_FORMAT_RG88
);
2079 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2081 if (!ctx
->_ImageTransferState
&&
2082 !srcPacking
->SwapBytes
&&
2083 ((dstFormat
== MESA_FORMAT_AL88
&&
2084 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2085 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2086 (dstFormat
== MESA_FORMAT_GR88
&&
2087 baseInternalFormat
== srcFormat
)) &&
2088 srcType
== GL_UNSIGNED_BYTE
&&
2090 /* simple memcpy path */
2091 memcpy_texture(ctx
, dims
,
2093 dstRowStride
, dstSlices
,
2094 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2095 srcAddr
, srcPacking
);
2097 else if (!ctx
->_ImageTransferState
&&
2099 srcType
== GL_UNSIGNED_BYTE
&&
2100 can_swizzle(baseInternalFormat
) &&
2101 can_swizzle(srcFormat
)) {
2104 /* dstmap - how to swizzle from RGBA to dst format:
2106 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2107 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2108 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2118 if ((littleEndian
&& dstFormat
== MESA_FORMAT_GR88
) ||
2119 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88
)) {
2128 dstmap
[2] = ZERO
; /* ? */
2129 dstmap
[3] = ONE
; /* ? */
2131 _mesa_swizzle_ubyte_image(ctx
, dims
,
2136 dstRowStride
, dstSlices
,
2137 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2142 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2145 srcWidth
, srcHeight
, srcDepth
,
2146 srcFormat
, srcType
, srcAddr
,
2148 const GLubyte
*src
= tempImage
;
2149 GLint img
, row
, col
;
2152 for (img
= 0; img
< srcDepth
; img
++) {
2153 GLubyte
*dstRow
= dstSlices
[img
];
2154 for (row
= 0; row
< srcHeight
; row
++) {
2155 GLushort
*dstUS
= (GLushort
*) dstRow
;
2156 if (dstFormat
== MESA_FORMAT_AL88
||
2157 dstFormat
== MESA_FORMAT_GR88
) {
2158 for (col
= 0; col
< srcWidth
; col
++) {
2159 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2160 dstUS
[col
] = PACK_COLOR_88( src
[1],
2166 for (col
= 0; col
< srcWidth
; col
++) {
2167 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2168 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2173 dstRow
+= dstRowStride
;
2176 free((void *) tempImage
);
2183 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2186 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2188 const GLboolean littleEndian
= _mesa_little_endian();
2189 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2191 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2192 dstFormat
== MESA_FORMAT_AL1616_REV
||
2193 dstFormat
== MESA_FORMAT_RG1616
||
2194 dstFormat
== MESA_FORMAT_RG1616_REV
);
2195 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2197 if (!ctx
->_ImageTransferState
&&
2198 !srcPacking
->SwapBytes
&&
2199 ((dstFormat
== MESA_FORMAT_AL1616
&&
2200 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2201 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2202 (dstFormat
== MESA_FORMAT_RG1616
&&
2203 baseInternalFormat
== srcFormat
)) &&
2204 srcType
== GL_UNSIGNED_SHORT
&&
2206 /* simple memcpy path */
2207 memcpy_texture(ctx
, dims
,
2209 dstRowStride
, dstSlices
,
2210 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2211 srcAddr
, srcPacking
);
2215 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2218 srcWidth
, srcHeight
, srcDepth
,
2219 srcFormat
, srcType
, srcAddr
,
2221 ctx
->_ImageTransferState
);
2222 const GLfloat
*src
= tempImage
;
2223 GLint img
, row
, col
;
2226 for (img
= 0; img
< srcDepth
; img
++) {
2227 GLubyte
*dstRow
= dstSlices
[img
];
2228 for (row
= 0; row
< srcHeight
; row
++) {
2229 GLuint
*dstUI
= (GLuint
*) dstRow
;
2230 if (dstFormat
== MESA_FORMAT_AL1616
||
2231 dstFormat
== MESA_FORMAT_RG1616
) {
2232 for (col
= 0; col
< srcWidth
; col
++) {
2235 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2236 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2237 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2242 for (col
= 0; col
< srcWidth
; col
++) {
2245 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2246 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2247 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2251 dstRow
+= dstRowStride
;
2254 free((void *) tempImage
);
2260 /* Texstore for R16, A16, L16, I16. */
2262 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2264 const GLboolean littleEndian
= _mesa_little_endian();
2265 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2267 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2268 dstFormat
== MESA_FORMAT_A16
||
2269 dstFormat
== MESA_FORMAT_L16
||
2270 dstFormat
== MESA_FORMAT_I16
);
2271 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2273 if (!ctx
->_ImageTransferState
&&
2274 !srcPacking
->SwapBytes
&&
2275 baseInternalFormat
== srcFormat
&&
2276 srcType
== GL_UNSIGNED_SHORT
&&
2278 /* simple memcpy path */
2279 memcpy_texture(ctx
, dims
,
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
[img
];
2300 for (row
= 0; row
< srcHeight
; row
++) {
2301 GLushort
*dstUS
= (GLushort
*) dstRow
;
2302 for (col
= 0; col
< srcWidth
; col
++) {
2305 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2309 dstRow
+= dstRowStride
;
2312 free((void *) tempImage
);
2319 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2321 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2323 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2324 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
2326 if (!ctx
->_ImageTransferState
&&
2327 !srcPacking
->SwapBytes
&&
2328 baseInternalFormat
== GL_RGBA
&&
2329 srcFormat
== GL_RGBA
&&
2330 srcType
== GL_UNSIGNED_SHORT
) {
2331 /* simple memcpy path */
2332 memcpy_texture(ctx
, dims
,
2334 dstRowStride
, dstSlices
,
2335 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2336 srcAddr
, srcPacking
);
2340 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2343 srcWidth
, srcHeight
, srcDepth
,
2344 srcFormat
, srcType
, srcAddr
,
2346 ctx
->_ImageTransferState
);
2347 const GLfloat
*src
= tempImage
;
2348 GLint img
, row
, col
;
2351 for (img
= 0; img
< srcDepth
; img
++) {
2352 GLubyte
*dstRow
= dstSlices
[img
];
2353 for (row
= 0; row
< srcHeight
; row
++) {
2354 GLushort
*dstUS
= (GLushort
*) dstRow
;
2355 for (col
= 0; col
< srcWidth
; col
++) {
2356 GLushort r
, g
, b
, a
;
2358 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2359 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2360 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2361 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2368 dstRow
+= dstRowStride
;
2371 free((void *) tempImage
);
2378 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2380 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2382 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2383 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2385 if (!ctx
->_ImageTransferState
&&
2386 !srcPacking
->SwapBytes
&&
2387 baseInternalFormat
== GL_RGBA
&&
2388 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2389 srcFormat
== GL_RGBA
&&
2390 srcType
== GL_SHORT
) {
2391 /* simple memcpy path */
2392 memcpy_texture(ctx
, dims
,
2394 dstRowStride
, dstSlices
,
2395 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2396 srcAddr
, srcPacking
);
2400 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2403 srcWidth
, srcHeight
, srcDepth
,
2404 srcFormat
, srcType
, srcAddr
,
2406 ctx
->_ImageTransferState
);
2407 const GLfloat
*src
= tempImage
;
2408 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2409 GLint img
, row
, col
;
2414 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2415 * 3 or 4 components/pixel here.
2417 for (img
= 0; img
< srcDepth
; img
++) {
2418 GLubyte
*dstRow
= dstSlices
[img
];
2419 for (row
= 0; row
< srcHeight
; row
++) {
2420 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2421 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2422 for (col
= 0; col
< srcWidth
; col
++) {
2424 for (c
= 0; c
< comps
; c
++) {
2426 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2427 dstRowS
[col
* comps
+ c
] = p
;
2430 dstRow
+= dstRowStride
;
2431 src
+= 4 * srcWidth
;
2433 for (col
= 0; col
< srcWidth
; col
++) {
2435 for (c
= 0; c
< comps
; c
++) {
2437 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2438 dstRowS
[col
* comps
+ c
] = p
;
2441 dstRow
+= dstRowStride
;
2442 src
+= 3 * srcWidth
;
2446 free((void *) tempImage
);
2453 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2455 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2457 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2458 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2460 if (!ctx
->_ImageTransferState
&&
2461 !srcPacking
->SwapBytes
&&
2462 baseInternalFormat
== GL_RGB
&&
2463 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2464 /* simple memcpy path */
2465 memcpy_texture(ctx
, dims
,
2467 dstRowStride
, dstSlices
,
2468 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2469 srcAddr
, srcPacking
);
2473 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2476 srcWidth
, srcHeight
, srcDepth
,
2477 srcFormat
, srcType
, srcAddr
,
2479 const GLubyte
*src
= tempImage
;
2480 GLint img
, row
, col
;
2483 for (img
= 0; img
< srcDepth
; img
++) {
2484 GLubyte
*dstRow
= dstSlices
[img
];
2485 for (row
= 0; row
< srcHeight
; row
++) {
2486 for (col
= 0; col
< srcWidth
; col
++) {
2487 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2492 dstRow
+= dstRowStride
;
2495 free((void *) tempImage
);
2502 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2505 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2507 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2509 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2510 dstFormat
== MESA_FORMAT_L8
||
2511 dstFormat
== MESA_FORMAT_I8
||
2512 dstFormat
== MESA_FORMAT_R8
);
2513 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2515 if (!ctx
->_ImageTransferState
&&
2516 !srcPacking
->SwapBytes
&&
2517 baseInternalFormat
== srcFormat
&&
2518 srcType
== GL_UNSIGNED_BYTE
) {
2519 /* simple memcpy path */
2520 memcpy_texture(ctx
, dims
,
2522 dstRowStride
, dstSlices
,
2523 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2524 srcAddr
, srcPacking
);
2526 else if (!ctx
->_ImageTransferState
&&
2527 srcType
== GL_UNSIGNED_BYTE
&&
2528 can_swizzle(baseInternalFormat
) &&
2529 can_swizzle(srcFormat
)) {
2532 /* dstmap - how to swizzle from RGBA to dst format:
2534 if (dstFormat
== MESA_FORMAT_A8
) {
2540 dstmap
[1] = ZERO
; /* ? */
2541 dstmap
[2] = ZERO
; /* ? */
2542 dstmap
[3] = ONE
; /* ? */
2544 _mesa_swizzle_ubyte_image(ctx
, dims
,
2549 dstRowStride
, dstSlices
,
2550 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2555 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2558 srcWidth
, srcHeight
, srcDepth
,
2559 srcFormat
, srcType
, srcAddr
,
2561 const GLubyte
*src
= tempImage
;
2562 GLint img
, row
, col
;
2565 for (img
= 0; img
< srcDepth
; img
++) {
2566 GLubyte
*dstRow
= dstSlices
[img
];
2567 for (row
= 0; row
< srcHeight
; row
++) {
2568 for (col
= 0; col
< srcWidth
; col
++) {
2569 dstRow
[col
] = src
[col
];
2571 dstRow
+= dstRowStride
;
2575 free((void *) tempImage
);
2583 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2586 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2588 const GLboolean littleEndian
= _mesa_little_endian();
2590 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2592 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2593 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2594 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2595 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2596 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2597 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2598 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2599 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2601 /* always just memcpy since no pixel transfer ops apply */
2602 memcpy_texture(ctx
, dims
,
2604 dstRowStride
, dstSlices
,
2605 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2606 srcAddr
, srcPacking
);
2608 /* Check if we need byte swapping */
2609 /* XXX the logic here _might_ be wrong */
2610 if (srcPacking
->SwapBytes
^
2611 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2612 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2615 for (img
= 0; img
< srcDepth
; img
++) {
2616 GLubyte
*dstRow
= dstSlices
[img
];
2617 for (row
= 0; row
< srcHeight
; row
++) {
2618 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2619 dstRow
+= dstRowStride
;
2627 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2629 const GLboolean littleEndian
= _mesa_little_endian();
2630 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2632 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2633 ASSERT(texelBytes
== 2);
2634 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2635 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2636 (srcFormat
== GL_DUDV_ATI
));
2637 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2639 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2641 /* simple memcpy path */
2642 memcpy_texture(ctx
, dims
,
2644 dstRowStride
, dstSlices
,
2645 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2646 srcAddr
, srcPacking
);
2648 else if (srcType
== GL_BYTE
) {
2651 /* dstmap - how to swizzle from RGBA to dst format:
2661 dstmap
[2] = ZERO
; /* ? */
2662 dstmap
[3] = ONE
; /* ? */
2664 _mesa_swizzle_ubyte_image(ctx
, dims
,
2665 GL_LUMINANCE_ALPHA
, /* hack */
2666 GL_UNSIGNED_BYTE
, /* hack */
2667 GL_LUMINANCE_ALPHA
, /* hack */
2669 dstRowStride
, dstSlices
,
2670 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2674 /* general path - note this is defined for 2d textures only */
2675 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2676 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2677 srcFormat
, srcType
);
2678 GLbyte
*tempImage
, *dst
, *src
;
2681 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2682 * components
* sizeof(GLbyte
));
2686 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2687 srcWidth
, srcHeight
,
2692 for (row
= 0; row
< srcHeight
; row
++) {
2693 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2694 dst
, srcFormat
, srcType
, src
,
2696 dst
+= srcWidth
* components
;
2701 dst
= (GLbyte
*) dstSlices
[0];
2702 for (row
= 0; row
< srcHeight
; row
++) {
2703 memcpy(dst
, src
, srcWidth
* texelBytes
);
2704 dst
+= dstRowStride
;
2705 src
+= srcWidth
* texelBytes
;
2707 free((void *) tempImage
);
2714 * Store a texture in a signed normalized 8-bit format.
2717 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2719 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2721 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2722 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2723 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2724 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2725 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2727 if (!ctx
->_ImageTransferState
&&
2728 !srcPacking
->SwapBytes
&&
2729 baseInternalFormat
== srcFormat
&&
2730 srcType
== GL_BYTE
) {
2731 /* simple memcpy path */
2732 memcpy_texture(ctx
, dims
,
2734 dstRowStride
, dstSlices
,
2735 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2736 srcAddr
, srcPacking
);
2740 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2743 srcWidth
, srcHeight
, srcDepth
,
2744 srcFormat
, srcType
, srcAddr
,
2746 ctx
->_ImageTransferState
);
2747 const GLfloat
*src
= tempImage
;
2748 GLint img
, row
, col
;
2751 for (img
= 0; img
< srcDepth
; img
++) {
2752 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2753 for (row
= 0; row
< srcHeight
; row
++) {
2754 for (col
= 0; col
< srcWidth
; col
++) {
2755 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2757 dstRow
+= dstRowStride
;
2761 free((void *) tempImage
);
2768 * Store a texture in a signed normalized two-channel 16-bit format.
2771 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2773 const GLboolean littleEndian
= _mesa_little_endian();
2774 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2776 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2777 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2778 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2780 if (!ctx
->_ImageTransferState
&&
2781 !srcPacking
->SwapBytes
&&
2782 baseInternalFormat
== srcFormat
&&
2783 srcType
== GL_BYTE
&&
2785 /* simple memcpy path */
2786 memcpy_texture(ctx
, dims
,
2788 dstRowStride
, dstSlices
,
2789 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2790 srcAddr
, srcPacking
);
2794 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2797 srcWidth
, srcHeight
, srcDepth
,
2798 srcFormat
, srcType
, srcAddr
,
2800 ctx
->_ImageTransferState
);
2801 const GLfloat
*src
= tempImage
;
2802 GLint img
, row
, col
;
2805 for (img
= 0; img
< srcDepth
; img
++) {
2806 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2807 for (row
= 0; row
< srcHeight
; row
++) {
2808 GLbyte
*dst
= dstRow
;
2809 for (col
= 0; col
< srcWidth
; col
++) {
2810 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2811 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2815 dstRow
+= dstRowStride
;
2818 free((void *) tempImage
);
2823 /* Texstore for signed R16, A16, L16, I16. */
2825 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2827 const GLboolean littleEndian
= _mesa_little_endian();
2828 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2830 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2831 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2832 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2833 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2834 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2836 if (!ctx
->_ImageTransferState
&&
2837 !srcPacking
->SwapBytes
&&
2838 baseInternalFormat
== srcFormat
&&
2839 srcType
== GL_SHORT
&&
2841 /* simple memcpy path */
2842 memcpy_texture(ctx
, dims
,
2844 dstRowStride
, dstSlices
,
2845 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2846 srcAddr
, srcPacking
);
2850 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2853 srcWidth
, srcHeight
, srcDepth
,
2854 srcFormat
, srcType
, srcAddr
,
2856 ctx
->_ImageTransferState
);
2857 const GLfloat
*src
= tempImage
;
2858 GLint img
, row
, col
;
2861 for (img
= 0; img
< srcDepth
; img
++) {
2862 GLubyte
*dstRow
= dstSlices
[img
];
2863 for (row
= 0; row
< srcHeight
; row
++) {
2864 GLshort
*dstUS
= (GLshort
*) dstRow
;
2865 for (col
= 0; col
< srcWidth
; col
++) {
2868 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2872 dstRow
+= dstRowStride
;
2875 free((void *) tempImage
);
2881 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2884 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2886 const GLboolean littleEndian
= _mesa_little_endian();
2887 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2889 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2890 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2891 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2893 if (!ctx
->_ImageTransferState
&&
2894 !srcPacking
->SwapBytes
&&
2895 baseInternalFormat
== srcFormat
&&
2896 srcType
== GL_SHORT
&&
2898 /* simple memcpy path */
2899 memcpy_texture(ctx
, dims
,
2901 dstRowStride
, dstSlices
,
2902 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2903 srcAddr
, srcPacking
);
2907 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2910 srcWidth
, srcHeight
, srcDepth
,
2911 srcFormat
, srcType
, srcAddr
,
2913 ctx
->_ImageTransferState
);
2914 const GLfloat
*src
= tempImage
;
2915 GLint img
, row
, col
;
2918 for (img
= 0; img
< srcDepth
; img
++) {
2919 GLubyte
*dstRow
= dstSlices
[img
];
2920 for (row
= 0; row
< srcHeight
; row
++) {
2921 GLshort
*dst
= (GLshort
*) dstRow
;
2922 for (col
= 0; col
< srcWidth
; col
++) {
2925 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2926 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2932 dstRow
+= dstRowStride
;
2935 free((void *) tempImage
);
2941 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2944 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2946 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2948 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2949 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
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
*srcRow
= tempImage
;
2961 GLint img
, row
, col
;
2964 for (img
= 0; img
< srcDepth
; img
++) {
2965 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2966 for (row
= 0; row
< srcHeight
; row
++) {
2967 GLbyte
*dst
= dstRow
;
2968 for (col
= 0; col
< srcWidth
; col
++) {
2969 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2970 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2971 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2976 dstRow
+= dstRowStride
;
2979 free((void *) tempImage
);
2987 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2988 * MESA_FORMAT_SIGNED_RGBA8888_REV
2991 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2993 const GLboolean littleEndian
= _mesa_little_endian();
2994 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2996 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2997 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2998 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3000 if (!ctx
->_ImageTransferState
&&
3001 !srcPacking
->SwapBytes
&&
3002 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3003 baseInternalFormat
== GL_RGBA
&&
3004 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3005 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3006 /* simple memcpy path */
3007 memcpy_texture(ctx
, dims
,
3009 dstRowStride
, dstSlices
,
3010 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3011 srcAddr
, srcPacking
);
3013 else if (!ctx
->_ImageTransferState
&&
3014 !srcPacking
->SwapBytes
&&
3015 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3016 baseInternalFormat
== GL_RGBA
&&
3017 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3018 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3019 /* simple memcpy path */
3020 memcpy_texture(ctx
, dims
,
3022 dstRowStride
, dstSlices
,
3023 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3024 srcAddr
, srcPacking
);
3028 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3031 srcWidth
, srcHeight
, srcDepth
,
3032 srcFormat
, srcType
, srcAddr
,
3034 ctx
->_ImageTransferState
);
3035 const GLfloat
*srcRow
= tempImage
;
3036 GLint img
, row
, col
;
3039 for (img
= 0; img
< srcDepth
; img
++) {
3040 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
3041 for (row
= 0; row
< srcHeight
; row
++) {
3042 GLbyte
*dst
= dstRow
;
3043 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3044 for (col
= 0; col
< srcWidth
; col
++) {
3045 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3046 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3047 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3048 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3054 for (col
= 0; col
< srcWidth
; col
++) {
3055 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3056 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3057 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3058 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3063 dstRow
+= dstRowStride
;
3066 free((void *) tempImage
);
3073 * Store a combined depth/stencil texture image.
3076 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3078 const GLuint depthScale
= 0xffffff;
3079 const GLint srcRowStride
3080 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3083 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3084 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3085 srcFormat
== GL_DEPTH_COMPONENT
||
3086 srcFormat
== GL_STENCIL_INDEX
);
3087 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3089 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3090 ctx
->Pixel
.DepthBias
== 0.0f
&&
3091 !srcPacking
->SwapBytes
) {
3093 memcpy_texture(ctx
, dims
,
3095 dstRowStride
, dstSlices
,
3096 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3097 srcAddr
, srcPacking
);
3099 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3100 srcFormat
== GL_STENCIL_INDEX
) {
3101 /* In case we only upload depth we need to preserve the stencil */
3102 for (img
= 0; img
< srcDepth
; img
++) {
3103 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
3105 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3106 srcWidth
, srcHeight
,
3109 for (row
= 0; row
< srcHeight
; row
++) {
3110 GLuint depth
[MAX_WIDTH
];
3111 GLubyte stencil
[MAX_WIDTH
];
3113 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3115 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3116 keepstencil
= GL_TRUE
;
3118 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3119 keepdepth
= GL_TRUE
;
3122 if (keepdepth
== GL_FALSE
)
3123 /* the 24 depth bits will be in the low position: */
3124 _mesa_unpack_depth_span(ctx
, srcWidth
,
3125 GL_UNSIGNED_INT
, /* dst type */
3126 keepstencil
? depth
: dstRow
, /* dst addr */
3128 srcType
, src
, srcPacking
);
3130 if (keepstencil
== GL_FALSE
)
3131 /* get the 8-bit stencil values */
3132 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3133 GL_UNSIGNED_BYTE
, /* dst type */
3134 stencil
, /* dst addr */
3135 srcType
, src
, srcPacking
,
3136 ctx
->_ImageTransferState
);
3138 for (i
= 0; i
< srcWidth
; i
++) {
3140 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3142 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3145 src
+= srcRowStride
;
3146 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3155 * Store a combined depth/stencil texture image.
3158 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3160 const GLuint depthScale
= 0xffffff;
3161 const GLint srcRowStride
3162 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3165 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3166 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3167 srcFormat
== GL_DEPTH_COMPONENT
||
3168 srcFormat
== GL_STENCIL_INDEX
);
3169 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3170 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3172 for (img
= 0; img
< srcDepth
; img
++) {
3173 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
3175 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3176 srcWidth
, srcHeight
,
3179 for (row
= 0; row
< srcHeight
; row
++) {
3180 GLuint depth
[MAX_WIDTH
];
3181 GLubyte stencil
[MAX_WIDTH
];
3183 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3185 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3186 keepstencil
= GL_TRUE
;
3188 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3189 keepdepth
= GL_TRUE
;
3192 if (keepdepth
== GL_FALSE
)
3193 /* the 24 depth bits will be in the low position: */
3194 _mesa_unpack_depth_span(ctx
, srcWidth
,
3195 GL_UNSIGNED_INT
, /* dst type */
3196 keepstencil
? depth
: dstRow
, /* dst addr */
3198 srcType
, src
, srcPacking
);
3200 if (keepstencil
== GL_FALSE
)
3201 /* get the 8-bit stencil values */
3202 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3203 GL_UNSIGNED_BYTE
, /* dst type */
3204 stencil
, /* dst addr */
3205 srcType
, src
, srcPacking
,
3206 ctx
->_ImageTransferState
);
3208 /* merge stencil values into depth values */
3209 for (i
= 0; i
< srcWidth
; i
++) {
3211 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3213 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3216 src
+= srcRowStride
;
3217 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3225 * Store simple 8-bit/value stencil texture data.
3228 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3230 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3231 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3233 if (!ctx
->_ImageTransferState
&&
3234 !srcPacking
->SwapBytes
&&
3235 baseInternalFormat
== srcFormat
&&
3236 srcType
== GL_UNSIGNED_BYTE
) {
3237 /* simple memcpy path */
3238 memcpy_texture(ctx
, dims
,
3240 dstRowStride
, dstSlices
,
3241 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3242 srcAddr
, srcPacking
);
3245 const GLint srcRowStride
3246 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3249 for (img
= 0; img
< srcDepth
; img
++) {
3250 GLubyte
*dstRow
= dstSlices
[img
];
3252 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3253 srcWidth
, srcHeight
,
3256 for (row
= 0; row
< srcHeight
; row
++) {
3257 GLubyte stencil
[MAX_WIDTH
];
3260 /* get the 8-bit stencil values */
3261 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3262 GL_UNSIGNED_BYTE
, /* dst type */
3263 stencil
, /* dst addr */
3264 srcType
, src
, srcPacking
,
3265 ctx
->_ImageTransferState
);
3266 /* merge stencil values into depth values */
3267 for (i
= 0; i
< srcWidth
; i
++)
3268 dstRow
[i
] = stencil
[i
];
3270 src
+= srcRowStride
;
3271 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3282 * Store an image in any of the formats:
3283 * _mesa_texformat_rgba_float32
3284 * _mesa_texformat_rgb_float32
3285 * _mesa_texformat_alpha_float32
3286 * _mesa_texformat_luminance_float32
3287 * _mesa_texformat_luminance_alpha_float32
3288 * _mesa_texformat_intensity_float32
3291 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3293 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3294 const GLint components
= _mesa_components_in_format(baseFormat
);
3296 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3297 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3298 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3299 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3300 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3301 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3302 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3303 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3304 ASSERT(baseInternalFormat
== GL_RGBA
||
3305 baseInternalFormat
== GL_RGB
||
3306 baseInternalFormat
== GL_ALPHA
||
3307 baseInternalFormat
== GL_LUMINANCE
||
3308 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3309 baseInternalFormat
== GL_INTENSITY
||
3310 baseInternalFormat
== GL_RED
||
3311 baseInternalFormat
== GL_RG
);
3312 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
3314 if (!ctx
->_ImageTransferState
&&
3315 !srcPacking
->SwapBytes
&&
3316 baseInternalFormat
== srcFormat
&&
3317 baseInternalFormat
== baseFormat
&&
3318 srcType
== GL_FLOAT
) {
3319 /* simple memcpy path */
3320 memcpy_texture(ctx
, dims
,
3322 dstRowStride
, dstSlices
,
3323 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3324 srcAddr
, srcPacking
);
3328 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3331 srcWidth
, srcHeight
, srcDepth
,
3332 srcFormat
, srcType
, srcAddr
,
3334 ctx
->_ImageTransferState
);
3335 const GLfloat
*srcRow
= tempImage
;
3340 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3341 for (img
= 0; img
< srcDepth
; img
++) {
3342 GLubyte
*dstRow
= dstSlices
[img
];
3343 for (row
= 0; row
< srcHeight
; row
++) {
3344 memcpy(dstRow
, srcRow
, bytesPerRow
);
3345 dstRow
+= dstRowStride
;
3346 srcRow
+= srcWidth
* components
;
3350 free((void *) tempImage
);
3358 * As above, but store 16-bit floats.
3361 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3363 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3364 const GLint components
= _mesa_components_in_format(baseFormat
);
3366 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3367 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3368 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3369 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3370 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3371 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3372 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3373 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3374 ASSERT(baseInternalFormat
== GL_RGBA
||
3375 baseInternalFormat
== GL_RGB
||
3376 baseInternalFormat
== GL_ALPHA
||
3377 baseInternalFormat
== GL_LUMINANCE
||
3378 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3379 baseInternalFormat
== GL_INTENSITY
||
3380 baseInternalFormat
== GL_RED
||
3381 baseInternalFormat
== GL_RG
);
3382 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
3384 if (!ctx
->_ImageTransferState
&&
3385 !srcPacking
->SwapBytes
&&
3386 baseInternalFormat
== srcFormat
&&
3387 baseInternalFormat
== baseFormat
&&
3388 srcType
== GL_HALF_FLOAT_ARB
) {
3389 /* simple memcpy path */
3390 memcpy_texture(ctx
, dims
,
3392 dstRowStride
, dstSlices
,
3393 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3394 srcAddr
, srcPacking
);
3398 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3401 srcWidth
, srcHeight
, srcDepth
,
3402 srcFormat
, srcType
, srcAddr
,
3404 ctx
->_ImageTransferState
);
3405 const GLfloat
*src
= tempImage
;
3409 for (img
= 0; img
< srcDepth
; img
++) {
3410 GLubyte
*dstRow
= dstSlices
[img
];
3411 for (row
= 0; row
< srcHeight
; row
++) {
3412 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3414 for (i
= 0; i
< srcWidth
* components
; i
++) {
3415 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3417 dstRow
+= dstRowStride
;
3418 src
+= srcWidth
* components
;
3422 free((void *) tempImage
);
3428 /* non-normalized, signed int8 */
3430 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3432 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3433 const GLint components
= _mesa_components_in_format(baseFormat
);
3435 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3436 dstFormat
== MESA_FORMAT_RG_INT8
||
3437 dstFormat
== MESA_FORMAT_RGB_INT8
||
3438 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3439 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3440 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3441 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3442 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3443 ASSERT(baseInternalFormat
== GL_RGBA
||
3444 baseInternalFormat
== GL_RGB
||
3445 baseInternalFormat
== GL_RG
||
3446 baseInternalFormat
== GL_RED
||
3447 baseInternalFormat
== GL_ALPHA
||
3448 baseInternalFormat
== GL_LUMINANCE
||
3449 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3450 baseInternalFormat
== GL_INTENSITY
);
3451 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
3453 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3454 * to integer formats.
3456 if (!srcPacking
->SwapBytes
&&
3457 baseInternalFormat
== srcFormat
&&
3458 srcType
== GL_BYTE
) {
3459 /* simple memcpy path */
3460 memcpy_texture(ctx
, dims
,
3462 dstRowStride
, dstSlices
,
3463 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3464 srcAddr
, srcPacking
);
3468 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3471 srcWidth
, srcHeight
, srcDepth
,
3472 srcFormat
, srcType
, srcAddr
,
3474 const GLfloat
*src
= tempImage
;
3478 for (img
= 0; img
< srcDepth
; img
++) {
3479 GLubyte
*dstRow
= dstSlices
[img
];
3480 for (row
= 0; row
< srcHeight
; row
++) {
3481 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3483 for (i
= 0; i
< srcWidth
* components
; i
++) {
3484 dstTexel
[i
] = (GLbyte
) src
[i
];
3486 dstRow
+= dstRowStride
;
3487 src
+= srcWidth
* components
;
3491 free((void *) tempImage
);
3497 /* non-normalized, signed int16 */
3499 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3501 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3502 const GLint components
= _mesa_components_in_format(baseFormat
);
3504 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3505 dstFormat
== MESA_FORMAT_RG_INT16
||
3506 dstFormat
== MESA_FORMAT_RGB_INT16
||
3507 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3508 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3509 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3510 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3511 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3512 ASSERT(baseInternalFormat
== GL_RGBA
||
3513 baseInternalFormat
== GL_RGB
||
3514 baseInternalFormat
== GL_RG
||
3515 baseInternalFormat
== GL_RED
||
3516 baseInternalFormat
== GL_ALPHA
||
3517 baseInternalFormat
== GL_LUMINANCE
||
3518 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3519 baseInternalFormat
== GL_INTENSITY
);
3520 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
3522 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3523 * to integer formats.
3525 if (!srcPacking
->SwapBytes
&&
3526 baseInternalFormat
== srcFormat
&&
3527 srcType
== GL_SHORT
) {
3528 /* simple memcpy path */
3529 memcpy_texture(ctx
, dims
,
3531 dstRowStride
, dstSlices
,
3532 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3533 srcAddr
, srcPacking
);
3537 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3540 srcWidth
, srcHeight
, srcDepth
,
3541 srcFormat
, srcType
, srcAddr
,
3543 const GLfloat
*src
= tempImage
;
3547 for (img
= 0; img
< srcDepth
; img
++) {
3548 GLubyte
*dstRow
= dstSlices
[img
];
3549 for (row
= 0; row
< srcHeight
; row
++) {
3550 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3552 for (i
= 0; i
< srcWidth
* components
; i
++) {
3553 dstTexel
[i
] = (GLint
) src
[i
];
3555 dstRow
+= dstRowStride
;
3556 src
+= srcWidth
* components
;
3560 free((void *) tempImage
);
3566 /* non-normalized, signed int32 */
3568 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3570 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3571 const GLint components
= _mesa_components_in_format(baseFormat
);
3573 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3574 dstFormat
== MESA_FORMAT_RG_INT32
||
3575 dstFormat
== MESA_FORMAT_RGB_INT32
||
3576 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3577 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3578 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3579 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3580 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3581 ASSERT(baseInternalFormat
== GL_RGBA
||
3582 baseInternalFormat
== GL_RGB
||
3583 baseInternalFormat
== GL_RG
||
3584 baseInternalFormat
== GL_RED
||
3585 baseInternalFormat
== GL_ALPHA
||
3586 baseInternalFormat
== GL_LUMINANCE
||
3587 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3588 baseInternalFormat
== GL_INTENSITY
);
3589 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
3591 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3592 * to integer formats.
3594 if (!srcPacking
->SwapBytes
&&
3595 baseInternalFormat
== srcFormat
&&
3596 srcType
== GL_INT
) {
3597 /* simple memcpy path */
3598 memcpy_texture(ctx
, dims
,
3600 dstRowStride
, dstSlices
,
3601 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3602 srcAddr
, srcPacking
);
3606 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3609 srcWidth
, srcHeight
, srcDepth
,
3610 srcFormat
, srcType
, srcAddr
,
3612 const GLfloat
*src
= tempImage
;
3616 for (img
= 0; img
< srcDepth
; img
++) {
3617 GLubyte
*dstRow
= dstSlices
[img
];
3618 for (row
= 0; row
< srcHeight
; row
++) {
3619 GLint
*dstTexel
= (GLint
*) dstRow
;
3621 for (i
= 0; i
< srcWidth
* components
; i
++) {
3622 dstTexel
[i
] = (GLint
) src
[i
];
3624 dstRow
+= dstRowStride
;
3625 src
+= srcWidth
* components
;
3629 free((void *) tempImage
);
3635 /* non-normalized, unsigned int8 */
3637 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3639 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3640 const GLint components
= _mesa_components_in_format(baseFormat
);
3642 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3643 dstFormat
== MESA_FORMAT_RG_UINT8
||
3644 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3645 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3646 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3647 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3648 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3649 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3650 ASSERT(baseInternalFormat
== GL_RGBA
||
3651 baseInternalFormat
== GL_RGB
||
3652 baseInternalFormat
== GL_RG
||
3653 baseInternalFormat
== GL_RED
||
3654 baseInternalFormat
== GL_ALPHA
||
3655 baseInternalFormat
== GL_LUMINANCE
||
3656 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3657 baseInternalFormat
== GL_INTENSITY
);
3658 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3660 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3661 * to integer formats.
3663 if (!srcPacking
->SwapBytes
&&
3664 baseInternalFormat
== srcFormat
&&
3665 srcType
== GL_UNSIGNED_BYTE
) {
3666 /* simple memcpy path */
3667 memcpy_texture(ctx
, dims
,
3669 dstRowStride
, dstSlices
,
3670 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3671 srcAddr
, srcPacking
);
3675 const GLuint
*tempImage
=
3676 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3677 srcWidth
, srcHeight
, srcDepth
,
3678 srcFormat
, srcType
, srcAddr
, srcPacking
);
3679 const GLuint
*src
= tempImage
;
3683 for (img
= 0; img
< srcDepth
; img
++) {
3684 GLubyte
*dstRow
= dstSlices
[img
];
3685 for (row
= 0; row
< srcHeight
; row
++) {
3686 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3688 for (i
= 0; i
< srcWidth
* components
; i
++) {
3689 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3691 dstRow
+= dstRowStride
;
3692 src
+= srcWidth
* components
;
3696 free((void *) tempImage
);
3702 /* non-normalized, unsigned int16 */
3704 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3706 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3707 const GLint components
= _mesa_components_in_format(baseFormat
);
3709 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3710 dstFormat
== MESA_FORMAT_RG_UINT16
||
3711 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3712 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3713 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3714 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3715 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3716 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3717 ASSERT(baseInternalFormat
== GL_RGBA
||
3718 baseInternalFormat
== GL_RGB
||
3719 baseInternalFormat
== GL_RG
||
3720 baseInternalFormat
== GL_RED
||
3721 baseInternalFormat
== GL_ALPHA
||
3722 baseInternalFormat
== GL_LUMINANCE
||
3723 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3724 baseInternalFormat
== GL_INTENSITY
);
3725 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3727 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3728 * to integer formats.
3730 if (!srcPacking
->SwapBytes
&&
3731 baseInternalFormat
== srcFormat
&&
3732 srcType
== GL_UNSIGNED_SHORT
) {
3733 /* simple memcpy path */
3734 memcpy_texture(ctx
, dims
,
3736 dstRowStride
, dstSlices
,
3737 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3738 srcAddr
, srcPacking
);
3742 const GLuint
*tempImage
=
3743 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3744 srcWidth
, srcHeight
, srcDepth
,
3745 srcFormat
, srcType
, srcAddr
, srcPacking
);
3746 const GLuint
*src
= tempImage
;
3750 for (img
= 0; img
< srcDepth
; img
++) {
3751 GLubyte
*dstRow
= dstSlices
[img
];
3752 for (row
= 0; row
< srcHeight
; row
++) {
3753 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3755 for (i
= 0; i
< srcWidth
* components
; i
++) {
3756 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3758 dstRow
+= dstRowStride
;
3759 src
+= srcWidth
* components
;
3763 free((void *) tempImage
);
3769 /* non-normalized, unsigned int32 */
3771 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3773 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3774 const GLint components
= _mesa_components_in_format(baseFormat
);
3776 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3777 dstFormat
== MESA_FORMAT_RG_UINT32
||
3778 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3779 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3780 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3781 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3782 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3783 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3784 ASSERT(baseInternalFormat
== GL_RGBA
||
3785 baseInternalFormat
== GL_RGB
||
3786 baseInternalFormat
== GL_RG
||
3787 baseInternalFormat
== GL_RED
||
3788 baseInternalFormat
== GL_ALPHA
||
3789 baseInternalFormat
== GL_LUMINANCE
||
3790 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3791 baseInternalFormat
== GL_INTENSITY
);
3792 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3794 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3795 * to integer formats.
3797 if (!srcPacking
->SwapBytes
&&
3798 baseInternalFormat
== srcFormat
&&
3799 srcType
== GL_UNSIGNED_INT
) {
3800 /* simple memcpy path */
3801 memcpy_texture(ctx
, dims
,
3803 dstRowStride
, dstSlices
,
3804 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3805 srcAddr
, srcPacking
);
3809 const GLuint
*tempImage
=
3810 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3811 srcWidth
, srcHeight
, srcDepth
,
3812 srcFormat
, srcType
, srcAddr
, srcPacking
);
3813 const GLuint
*src
= tempImage
;
3817 for (img
= 0; img
< srcDepth
; img
++) {
3818 GLubyte
*dstRow
= dstSlices
[img
];
3819 for (row
= 0; row
< srcHeight
; row
++) {
3820 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3822 for (i
= 0; i
< srcWidth
* components
; i
++) {
3823 dstTexel
[i
] = src
[i
];
3825 dstRow
+= dstRowStride
;
3826 src
+= srcWidth
* components
;
3830 free((void *) tempImage
);
3838 #if FEATURE_EXT_texture_sRGB
3840 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3842 gl_format newDstFormat
;
3845 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3847 /* reuse normal rgb texstore code */
3848 newDstFormat
= MESA_FORMAT_RGB888
;
3850 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3852 dstRowStride
, dstSlices
,
3853 srcWidth
, srcHeight
, srcDepth
,
3855 srcAddr
, srcPacking
);
3861 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3863 gl_format newDstFormat
;
3866 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3868 /* reuse normal rgba texstore code */
3869 newDstFormat
= MESA_FORMAT_RGBA8888
;
3870 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3872 dstRowStride
, dstSlices
,
3873 srcWidth
, srcHeight
, srcDepth
,
3875 srcAddr
, srcPacking
);
3881 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3883 gl_format newDstFormat
;
3886 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3888 /* reuse normal rgba texstore code */
3889 newDstFormat
= MESA_FORMAT_ARGB8888
;
3891 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3893 dstRowStride
, dstSlices
,
3894 srcWidth
, srcHeight
, srcDepth
,
3896 srcAddr
, srcPacking
);
3902 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3904 gl_format newDstFormat
;
3907 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3909 newDstFormat
= MESA_FORMAT_L8
;
3911 /* _mesa_textore_a8 handles luminance8 too */
3912 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3914 dstRowStride
, dstSlices
,
3915 srcWidth
, srcHeight
, srcDepth
,
3917 srcAddr
, srcPacking
);
3923 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3925 gl_format newDstFormat
;
3928 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3930 /* reuse normal luminance/alpha texstore code */
3931 newDstFormat
= MESA_FORMAT_AL88
;
3933 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3935 dstRowStride
, dstSlices
,
3936 srcWidth
, srcHeight
, srcDepth
,
3938 srcAddr
, srcPacking
);
3944 /* these are used only in texstore_funcs[] below */
3945 #define _mesa_texstore_srgb8 NULL
3946 #define _mesa_texstore_srgba8 NULL
3947 #define _mesa_texstore_sargb8 NULL
3948 #define _mesa_texstore_sl8 NULL
3949 #define _mesa_texstore_sla8 NULL
3951 #endif /* FEATURE_EXT_texture_sRGB */
3954 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3956 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3958 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
3959 ASSERT(baseInternalFormat
== GL_RGB
);
3961 if (!ctx
->_ImageTransferState
&&
3962 !srcPacking
->SwapBytes
&&
3963 srcFormat
== GL_RGB
&&
3964 srcType
== GL_UNSIGNED_INT_5_9_9_9_REV
) {
3965 /* simple memcpy path */
3966 memcpy_texture(ctx
, dims
,
3968 dstRowStride
, dstSlices
,
3969 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3970 srcAddr
, srcPacking
);
3974 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3977 srcWidth
, srcHeight
, srcDepth
,
3978 srcFormat
, srcType
, srcAddr
,
3980 ctx
->_ImageTransferState
);
3981 const GLfloat
*srcRow
= tempImage
;
3982 GLint img
, row
, col
;
3985 for (img
= 0; img
< srcDepth
; img
++) {
3986 GLubyte
*dstRow
= dstSlices
[img
];
3987 for (row
= 0; row
< srcHeight
; row
++) {
3988 GLuint
*dstUI
= (GLuint
*)dstRow
;
3989 for (col
= 0; col
< srcWidth
; col
++) {
3990 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3992 dstRow
+= dstRowStride
;
3993 srcRow
+= srcWidth
* 3;
3997 free((void *) tempImage
);
4003 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
4005 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4007 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
4008 ASSERT(baseInternalFormat
== GL_RGB
);
4010 if (!ctx
->_ImageTransferState
&&
4011 !srcPacking
->SwapBytes
&&
4012 srcFormat
== GL_RGB
&&
4013 srcType
== GL_UNSIGNED_INT_10F_11F_11F_REV
) {
4014 /* simple memcpy path */
4015 memcpy_texture(ctx
, dims
,
4017 dstRowStride
, dstSlices
,
4018 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4019 srcAddr
, srcPacking
);
4023 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4026 srcWidth
, srcHeight
, srcDepth
,
4027 srcFormat
, srcType
, srcAddr
,
4029 ctx
->_ImageTransferState
);
4030 const GLfloat
*srcRow
= tempImage
;
4031 GLint img
, row
, col
;
4034 for (img
= 0; img
< srcDepth
; img
++) {
4035 GLubyte
*dstRow
= dstSlices
[img
];
4036 for (row
= 0; row
< srcHeight
; row
++) {
4037 GLuint
*dstUI
= (GLuint
*)dstRow
;
4038 for (col
= 0; col
< srcWidth
; col
++) {
4039 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
4041 dstRow
+= dstRowStride
;
4042 srcRow
+= srcWidth
* 3;
4046 free((void *) tempImage
);
4053 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
4055 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
4056 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
4057 srcFormat
== GL_DEPTH_COMPONENT
||
4058 srcFormat
== GL_STENCIL_INDEX
);
4059 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
4060 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
4062 if (srcFormat
== GL_DEPTH_STENCIL
&&
4063 ctx
->Pixel
.DepthScale
== 1.0f
&&
4064 ctx
->Pixel
.DepthBias
== 0.0f
&&
4065 !srcPacking
->SwapBytes
) {
4067 memcpy_texture(ctx
, dims
,
4069 dstRowStride
, dstSlices
,
4070 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4071 srcAddr
, srcPacking
);
4073 else if (srcFormat
== GL_DEPTH_COMPONENT
||
4074 srcFormat
== GL_STENCIL_INDEX
) {
4076 const GLint srcRowStride
4077 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
4080 /* In case we only upload depth we need to preserve the stencil */
4081 for (img
= 0; img
< srcDepth
; img
++) {
4082 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
4084 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
4085 srcWidth
, srcHeight
,
4088 for (row
= 0; row
< srcHeight
; row
++) {
4089 /* The unpack functions with:
4090 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4091 * only write their own dword, so the other dword (stencil
4092 * or depth) is preserved. */
4093 if (srcFormat
!= GL_STENCIL_INDEX
)
4094 _mesa_unpack_depth_span(ctx
, srcWidth
,
4095 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4096 dstRow
, /* dst addr */
4097 1.0f
, srcType
, src
, srcPacking
);
4099 if (srcFormat
!= GL_DEPTH_COMPONENT
)
4100 _mesa_unpack_stencil_span(ctx
, srcWidth
,
4101 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4102 dstRow
, /* dst addr */
4103 srcType
, src
, srcPacking
,
4104 ctx
->_ImageTransferState
);
4106 src
+= srcRowStride
;
4107 dstRow
+= dstRowStride
/ sizeof(uint64_t);
4115 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
4117 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4119 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
4120 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
4122 if (!srcPacking
->SwapBytes
&&
4123 dstFormat
== MESA_FORMAT_ARGB2101010_UINT
&&
4124 srcFormat
== GL_BGRA_INTEGER_EXT
&&
4125 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
4126 baseInternalFormat
== GL_RGBA
) {
4127 /* simple memcpy path */
4128 memcpy_texture(ctx
, dims
,
4130 dstRowStride
, dstSlices
,
4131 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4132 srcAddr
, srcPacking
);
4136 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
4139 srcWidth
, srcHeight
,
4140 srcDepth
, srcFormat
,
4143 const GLuint
*src
= tempImage
;
4144 GLint img
, row
, col
;
4147 for (img
= 0; img
< srcDepth
; img
++) {
4148 GLubyte
*dstRow
= dstSlices
[img
];
4150 for (row
= 0; row
< srcHeight
; row
++) {
4151 GLuint
*dstUI
= (GLuint
*) dstRow
;
4152 for (col
= 0; col
< srcWidth
; col
++) {
4158 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
4161 dstRow
+= dstRowStride
;
4164 free((void *) tempImage
);
4170 _mesa_texstore_null(TEXSTORE_PARAMS
)
4172 (void) ctx
; (void) dims
;
4173 (void) baseInternalFormat
;
4175 (void) dstRowStride
; (void) dstSlices
,
4176 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4177 (void) srcFormat
; (void) srcType
;
4181 /* should never happen */
4182 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4188 * Return the StoreTexImageFunc pointer to store an image in the given format.
4190 static StoreTexImageFunc
4191 _mesa_get_texstore_func(gl_format format
)
4193 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
4194 static GLboolean initialized
= GL_FALSE
;
4197 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
4199 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
4200 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
4201 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
4202 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
4203 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
4204 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
4205 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
4206 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
4207 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
4208 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
4209 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
4210 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
4211 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
4212 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
4213 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
4214 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
4215 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
4216 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
4217 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
4218 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
4219 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
4220 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
4221 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
4222 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
4223 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
4224 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
4225 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
4226 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
4227 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
4228 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
4229 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
4230 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
4231 table
[MESA_FORMAT_GR88
] = _mesa_texstore_unorm88
;
4232 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
4233 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
4234 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
4235 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
4236 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
4237 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
4238 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
4239 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
4240 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
4241 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
4242 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
4243 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
4244 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
4245 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
4246 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
4247 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
4248 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
4249 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4250 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4251 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4252 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4253 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
4254 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
4255 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4256 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4257 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4258 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4259 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4260 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4261 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
4262 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
4263 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4264 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4265 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
4266 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
4267 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4268 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4269 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
4270 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
4271 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
4272 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
4273 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
4274 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
4275 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
4276 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
4277 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
4278 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
4279 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
4280 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
4281 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
4282 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
4283 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
4284 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
4285 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
4286 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
4287 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
4288 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
4289 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
4290 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
4291 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
4292 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
4293 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
4294 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
4295 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
4296 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
4297 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
4298 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
4299 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
4300 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
4301 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
4302 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
4303 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
4304 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
4305 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
4306 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
4308 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4309 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4310 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4311 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4312 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4313 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4315 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
4316 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
4317 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
4318 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
4319 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
4320 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
4322 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
4323 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
4324 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
4325 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
4326 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
4327 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4329 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4330 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4331 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4332 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4333 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4334 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4336 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4337 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4338 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4339 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4340 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4341 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4342 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4343 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4344 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4345 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4346 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4347 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4349 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4350 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4351 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4352 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4353 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4354 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4355 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4356 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4357 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4358 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4359 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4360 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4362 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
4363 initialized
= GL_TRUE
;
4366 ASSERT(table
[format
]);
4367 return table
[format
];
4372 * Store user data into texture memory.
4373 * Called via glTex[Sub]Image1/2/3D()
4376 _mesa_texstore(TEXSTORE_PARAMS
)
4378 StoreTexImageFunc storeImage
;
4381 storeImage
= _mesa_get_texstore_func(dstFormat
);
4383 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4385 dstRowStride
, dstSlices
,
4386 srcWidth
, srcHeight
, srcDepth
,
4387 srcFormat
, srcType
, srcAddr
, srcPacking
);
4393 * Normally, we'll only _write_ texel data to a texture when we map it.
4394 * But if the user is providing depth or stencil values and the texture
4395 * image is a combined depth/stencil format, we'll actually read from
4396 * the texture buffer too (in order to insert the depth or stencil values.
4397 * \param userFormat the user-provided image format
4398 * \param texFormat the destination texture format
4401 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4403 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4404 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4405 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4407 return GL_MAP_WRITE_BIT
;
4412 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
4414 * The source of the image data may be user memory or a PBO. In the later
4415 * case, we'll map the PBO, copy from it, then unmap it.
4418 store_texsubimage(struct gl_context
*ctx
,
4419 struct gl_texture_image
*texImage
,
4420 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4421 GLint width
, GLint height
, GLint depth
,
4422 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4423 const struct gl_pixelstore_attrib
*packing
,
4427 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4428 const GLenum target
= texImage
->TexObject
->Target
;
4429 GLboolean success
= GL_FALSE
;
4430 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
4431 GLint srcImageStride
= 0;
4434 assert(xoffset
+ width
<= texImage
->Width
);
4435 assert(yoffset
+ height
<= texImage
->Height
);
4436 assert(zoffset
+ depth
<= texImage
->Depth
);
4442 case GL_TEXTURE_2D_ARRAY
:
4450 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4451 src
= (const GLubyte
*)
4452 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
4453 format
, type
, pixels
, packing
, caller
);
4457 /* compute slice info (and do some sanity checks) */
4460 case GL_TEXTURE_RECTANGLE
:
4461 case GL_TEXTURE_CUBE_MAP
:
4462 /* one image slice, nothing special needs to be done */
4465 assert(height
== 1);
4467 assert(yoffset
== 0);
4468 assert(zoffset
== 0);
4470 case GL_TEXTURE_1D_ARRAY
:
4472 assert(zoffset
== 0);
4474 sliceOffset
= yoffset
;
4477 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
4479 case GL_TEXTURE_2D_ARRAY
:
4481 sliceOffset
= zoffset
;
4484 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4488 /* we'll store 3D images as a series of slices */
4490 sliceOffset
= zoffset
;
4491 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4495 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4499 assert(numSlices
== 1 || srcImageStride
!= 0);
4501 for (slice
= 0; slice
< numSlices
; slice
++) {
4505 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4506 slice
+ sliceOffset
,
4507 xoffset
, yoffset
, width
, height
,
4508 mapMode
, &dstMap
, &dstRowStride
);
4510 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4511 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4512 * used for 3D images.
4514 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4515 texImage
->TexFormat
,
4518 width
, height
, 1, /* w, h, d */
4519 format
, type
, src
, packing
);
4521 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4524 src
+= srcImageStride
;
4531 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4533 _mesa_unmap_teximage_pbo(ctx
, packing
);
4539 * This is the fallback for Driver.TexImage1D().
4542 _mesa_store_teximage1d(struct gl_context
*ctx
,
4543 struct gl_texture_image
*texImage
,
4544 GLint internalFormat
,
4545 GLint width
, GLint border
,
4546 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4547 const struct gl_pixelstore_attrib
*packing
)
4552 /* allocate storage for texture data */
4553 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4555 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4559 store_texsubimage(ctx
, texImage
,
4560 0, 0, 0, width
, 1, 1,
4561 format
, type
, pixels
, packing
, "glTexImage1D");
4566 * This is the fallback for Driver.TexImage2D().
4569 _mesa_store_teximage2d(struct gl_context
*ctx
,
4570 struct gl_texture_image
*texImage
,
4571 GLint internalFormat
,
4572 GLint width
, GLint height
, GLint border
,
4573 GLenum format
, GLenum type
, const void *pixels
,
4574 const struct gl_pixelstore_attrib
*packing
)
4576 if (width
== 0 || height
== 0)
4579 /* allocate storage for texture data */
4580 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4581 width
, height
, 1)) {
4582 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4586 store_texsubimage(ctx
, texImage
,
4587 0, 0, 0, width
, height
, 1,
4588 format
, type
, pixels
, packing
, "glTexImage2D");
4594 * This is the fallback for Driver.TexImage3D().
4597 _mesa_store_teximage3d(struct gl_context
*ctx
,
4598 struct gl_texture_image
*texImage
,
4599 GLint internalFormat
,
4600 GLint width
, GLint height
, GLint depth
, GLint border
,
4601 GLenum format
, GLenum type
, const void *pixels
,
4602 const struct gl_pixelstore_attrib
*packing
)
4604 if (width
== 0 || height
== 0 || depth
== 0)
4607 /* allocate storage for texture data */
4608 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4609 width
, height
, depth
)) {
4610 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4614 store_texsubimage(ctx
, texImage
,
4615 0, 0, 0, width
, height
, depth
,
4616 format
, type
, pixels
, packing
, "glTexImage3D");
4623 * This is the fallback for Driver.TexSubImage1D().
4626 _mesa_store_texsubimage1d(struct gl_context
*ctx
,
4627 struct gl_texture_image
*texImage
,
4628 GLint xoffset
, GLint width
,
4629 GLenum format
, GLenum type
, const void *pixels
,
4630 const struct gl_pixelstore_attrib
*packing
)
4632 store_texsubimage(ctx
, texImage
,
4633 xoffset
, 0, 0, width
, 1, 1,
4634 format
, type
, pixels
, packing
, "glTexSubImage1D");
4640 * This is the fallback for Driver.TexSubImage2D().
4643 _mesa_store_texsubimage2d(struct gl_context
*ctx
,
4644 struct gl_texture_image
*texImage
,
4645 GLint xoffset
, GLint yoffset
,
4646 GLint width
, GLint height
,
4647 GLenum format
, GLenum type
, const void *pixels
,
4648 const struct gl_pixelstore_attrib
*packing
)
4650 store_texsubimage(ctx
, texImage
,
4651 xoffset
, yoffset
, 0, width
, height
, 1,
4652 format
, type
, pixels
, packing
, "glTexSubImage2D");
4657 * This is the fallback for Driver.TexSubImage3D().
4660 _mesa_store_texsubimage3d(struct gl_context
*ctx
,
4661 struct gl_texture_image
*texImage
,
4662 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4663 GLint width
, GLint height
, GLint depth
,
4664 GLenum format
, GLenum type
, const void *pixels
,
4665 const struct gl_pixelstore_attrib
*packing
)
4667 store_texsubimage(ctx
, texImage
,
4668 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4669 format
, type
, pixels
, packing
, "glTexSubImage3D");
4674 * Fallback for Driver.CompressedTexImage1D()
4677 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4678 struct gl_texture_image
*texImage
,
4679 GLint internalFormat
,
4680 GLint width
, GLint border
,
4681 GLsizei imageSize
, const GLvoid
*data
)
4683 /* no compressed 1D image formats at this time */
4685 (void) internalFormat
;
4686 (void) width
; (void) border
;
4687 (void) imageSize
; (void) data
;
4694 * Fallback for Driver.CompressedTexImage2D()
4697 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4698 struct gl_texture_image
*texImage
,
4699 GLint internalFormat
,
4700 GLint width
, GLint height
, GLint border
,
4701 GLsizei imageSize
, const GLvoid
*data
)
4703 /* This is pretty simple, because unlike the general texstore path we don't
4704 * have to worry about the usual image unpacking or image transfer
4708 ASSERT(texImage
->Width
> 0);
4709 ASSERT(texImage
->Height
> 0);
4710 ASSERT(texImage
->Depth
== 1);
4712 /* allocate storage for texture data */
4713 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4714 width
, height
, 1)) {
4715 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4719 _mesa_store_compressed_texsubimage2d(ctx
, texImage
,
4722 texImage
->TexFormat
,
4729 * Fallback for Driver.CompressedTexImage3D()
4732 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4733 struct gl_texture_image
*texImage
,
4734 GLint internalFormat
,
4735 GLint width
, GLint height
, GLint depth
,
4737 GLsizei imageSize
, const GLvoid
*data
)
4739 /* this space intentionally left blank */
4741 (void) internalFormat
;
4742 (void) width
; (void) height
; (void) depth
;
4744 (void) imageSize
; (void) data
;
4751 * Fallback for Driver.CompressedTexSubImage1D()
4754 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
,
4755 struct gl_texture_image
*texImage
,
4756 GLint xoffset
, GLsizei width
,
4758 GLsizei imageSize
, const GLvoid
*data
)
4760 /* there are no compressed 1D texture formats yet */
4762 (void) xoffset
; (void) width
;
4764 (void) imageSize
; (void) data
;
4770 * Fallback for Driver.CompressedTexSubImage2D()
4773 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
,
4774 struct gl_texture_image
*texImage
,
4775 GLint xoffset
, GLint yoffset
,
4776 GLsizei width
, GLsizei height
,
4778 GLsizei imageSize
, const GLvoid
*data
)
4780 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
4784 const gl_format texFormat
= texImage
->TexFormat
;
4787 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4789 /* these should have been caught sooner */
4790 ASSERT((width
% bw
) == 0 || width
< bw
);
4791 ASSERT((height
% bh
) == 0 || height
< bh
);
4792 ASSERT((xoffset
% bw
) == 0);
4793 ASSERT((yoffset
% bh
) == 0);
4795 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4796 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4798 "glCompressedTexSubImage2D");
4802 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4803 src
= (const GLubyte
*) data
;
4805 /* Map dest texture buffer */
4806 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4807 xoffset
, yoffset
, width
, height
,
4809 &dstMap
, &dstRowStride
);
4812 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4813 rows
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4815 /* copy rows of blocks */
4816 for (i
= 0; i
< rows
; i
++) {
4817 memcpy(dstMap
, src
, bytesPerRow
);
4818 dstMap
+= dstRowStride
;
4819 src
+= srcRowStride
;
4822 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4825 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage2D");
4828 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4833 * Fallback for Driver.CompressedTexSubImage3D()
4836 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
,
4837 struct gl_texture_image
*texImage
,
4838 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4839 GLsizei width
, GLsizei height
, GLsizei depth
,
4841 GLsizei imageSize
, const GLvoid
*data
)
4843 /* there are no compressed 3D texture formats yet */
4845 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4846 (void) width
; (void) height
; (void) depth
;
4848 (void) imageSize
; (void) data
;