2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage = _mesa_store_teximage;
41 * ctx->Driver.TexSubImage = _mesa_store_texsubimage;
44 * Texture image processing is actually kind of complicated. We have to do:
45 * Format/type conversions
47 * pixel transfer (scale, bais, lookup, etc)
49 * These functions can handle most everything, including processing full
50 * images and sub-images.
55 #include "bufferobj.h"
57 #include "format_pack.h"
65 #include "texcompress.h"
66 #include "texcompress_fxt1.h"
67 #include "texcompress_rgtc.h"
68 #include "texcompress_s3tc.h"
69 #include "texcompress_etc.h"
73 #include "glformats.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
= 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
= 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
= 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
= malloc(srcWidth
* srcHeight
* srcDepth
504 * texComponents
* sizeof(GLuint
));
510 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
512 n
= srcWidth
* srcHeight
* srcDepth
;
513 for (i
= 0; i
< n
; i
++) {
515 for (k
= 0; k
< texComponents
; k
++) {
518 newImage
[i
* texComponents
+ k
] = 0;
520 newImage
[i
* texComponents
+ k
] = 1;
522 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
527 tempImage
= newImage
;
536 * Make a temporary (color) texture image with GLubyte components.
537 * Apply all needed pixel unpacking and pixel transfer operations.
538 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
539 * Suppose the user specifies GL_LUMINANCE as the internal texture format
540 * but the graphics hardware doesn't support luminance textures. So, we might
541 * use an RGB hardware format instead.
542 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
544 * \param ctx the rendering context
545 * \param dims image dimensions: 1, 2 or 3
546 * \param logicalBaseFormat basic texture derived from the user's
547 * internal texture format value
548 * \param textureBaseFormat the actual basic format of the texture
549 * \param srcWidth source image width
550 * \param srcHeight source image height
551 * \param srcDepth source image depth
552 * \param srcFormat source image format
553 * \param srcType source image type
554 * \param srcAddr source image address
555 * \param srcPacking source image pixel packing
556 * \return resulting image with format = textureBaseFormat and type = GLubyte.
559 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
560 GLenum logicalBaseFormat
,
561 GLenum textureBaseFormat
,
562 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
563 GLenum srcFormat
, GLenum srcType
,
564 const GLvoid
*srcAddr
,
565 const struct gl_pixelstore_attrib
*srcPacking
)
567 GLuint transferOps
= ctx
->_ImageTransferState
;
568 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
570 GLubyte
*tempImage
, *dst
;
572 ASSERT(dims
>= 1 && dims
<= 3);
574 ASSERT(logicalBaseFormat
== GL_RGBA
||
575 logicalBaseFormat
== GL_RGB
||
576 logicalBaseFormat
== GL_RG
||
577 logicalBaseFormat
== GL_RED
||
578 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
579 logicalBaseFormat
== GL_LUMINANCE
||
580 logicalBaseFormat
== GL_ALPHA
||
581 logicalBaseFormat
== GL_INTENSITY
);
583 ASSERT(textureBaseFormat
== GL_RGBA
||
584 textureBaseFormat
== GL_RGB
||
585 textureBaseFormat
== GL_RG
||
586 textureBaseFormat
== GL_RED
||
587 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
588 textureBaseFormat
== GL_LUMINANCE
||
589 textureBaseFormat
== GL_ALPHA
||
590 textureBaseFormat
== GL_INTENSITY
);
592 /* unpack and transfer the source image */
593 tempImage
= 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
= 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
,
926 mesa_format dstFormat
,
929 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
930 GLenum srcFormat
, GLenum srcType
,
931 const GLvoid
*srcAddr
,
932 const struct gl_pixelstore_attrib
*srcPacking
)
934 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
936 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
937 srcWidth
, srcHeight
, srcFormat
, srcType
);
938 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
939 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
940 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
941 const GLint bytesPerRow
= srcWidth
* texelBytes
;
943 if (dstRowStride
== srcRowStride
&&
944 dstRowStride
== bytesPerRow
) {
945 /* memcpy image by image */
947 for (img
= 0; img
< srcDepth
; img
++) {
948 GLubyte
*dstImage
= dstSlices
[img
];
949 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
950 srcImage
+= srcImageStride
;
954 /* memcpy row by row */
956 for (img
= 0; img
< srcDepth
; img
++) {
957 const GLubyte
*srcRow
= srcImage
;
958 GLubyte
*dstRow
= dstSlices
[img
];
959 for (row
= 0; row
< srcHeight
; row
++) {
960 memcpy(dstRow
, srcRow
, bytesPerRow
);
961 dstRow
+= dstRowStride
;
962 srcRow
+= srcRowStride
;
964 srcImage
+= srcImageStride
;
971 * General-case function for storing a color texture images with
972 * components that can be represented with ubytes. Example destination
973 * texture formats are MESA_FORMAT_ARGB888, ARGB4444, RGB565.
976 store_ubyte_texture(TEXSTORE_PARAMS
)
978 const GLint srcRowStride
= srcWidth
* 4 * sizeof(GLubyte
);
979 GLubyte
*tempImage
, *src
;
982 tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
985 srcWidth
, srcHeight
, srcDepth
,
986 srcFormat
, srcType
, srcAddr
,
992 for (img
= 0; img
< srcDepth
; img
++) {
993 _mesa_pack_ubyte_rgba_rect(dstFormat
, srcWidth
, srcHeight
,
995 dstSlices
[img
], dstRowStride
);
996 src
+= srcHeight
* srcRowStride
;
1007 * Store a 32-bit integer or float depth component texture image.
1010 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1012 const GLuint depthScale
= 0xffffffff;
1015 ASSERT(dstFormat
== MESA_FORMAT_Z_UNORM32
||
1016 dstFormat
== MESA_FORMAT_Z_FLOAT32
);
1017 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
1019 if (dstFormat
== MESA_FORMAT_Z_UNORM32
)
1020 dstType
= GL_UNSIGNED_INT
;
1027 for (img
= 0; img
< srcDepth
; img
++) {
1028 GLubyte
*dstRow
= dstSlices
[img
];
1029 for (row
= 0; row
< srcHeight
; row
++) {
1030 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1031 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1032 _mesa_unpack_depth_span(ctx
, srcWidth
,
1034 depthScale
, srcType
, src
, srcPacking
);
1035 dstRow
+= dstRowStride
;
1044 * Store a 24-bit integer depth component texture image.
1047 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1049 const GLuint depthScale
= 0xffffff;
1052 ASSERT(dstFormat
== MESA_FORMAT_Z24_UNORM_X8_UINT
);
1057 for (img
= 0; img
< srcDepth
; img
++) {
1058 GLubyte
*dstRow
= dstSlices
[img
];
1059 for (row
= 0; row
< srcHeight
; row
++) {
1060 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1061 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1062 _mesa_unpack_depth_span(ctx
, srcWidth
,
1063 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1064 depthScale
, srcType
, src
, srcPacking
);
1065 dstRow
+= dstRowStride
;
1074 * Store a 24-bit integer depth component texture image.
1077 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1079 const GLuint depthScale
= 0xffffff;
1082 ASSERT(dstFormat
== MESA_FORMAT_X8_UINT_Z24_UNORM
);
1087 for (img
= 0; img
< srcDepth
; img
++) {
1088 GLubyte
*dstRow
= dstSlices
[img
];
1089 for (row
= 0; row
< srcHeight
; row
++) {
1090 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1091 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1092 GLuint
*dst
= (GLuint
*) dstRow
;
1094 _mesa_unpack_depth_span(ctx
, srcWidth
,
1095 GL_UNSIGNED_INT
, dst
,
1096 depthScale
, srcType
, src
, srcPacking
);
1097 for (i
= 0; i
< srcWidth
; i
++)
1099 dstRow
+= dstRowStride
;
1108 * Store a 16-bit integer depth component texture image.
1111 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1113 const GLuint depthScale
= 0xffff;
1115 ASSERT(dstFormat
== MESA_FORMAT_Z_UNORM16
);
1116 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1121 for (img
= 0; img
< srcDepth
; img
++) {
1122 GLubyte
*dstRow
= dstSlices
[img
];
1123 for (row
= 0; row
< srcHeight
; row
++) {
1124 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1125 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1126 GLushort
*dst16
= (GLushort
*) dstRow
;
1127 _mesa_unpack_depth_span(ctx
, srcWidth
,
1128 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1129 srcType
, src
, srcPacking
);
1130 dstRow
+= dstRowStride
;
1139 * Store an rgb565 or rgb565_rev texture image.
1142 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1144 ASSERT(dstFormat
== MESA_FORMAT_B5G6R5_UNORM
||
1145 dstFormat
== MESA_FORMAT_R5G6B5_UNORM
);
1146 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1148 if (!ctx
->_ImageTransferState
&&
1149 !srcPacking
->SwapBytes
&&
1150 baseInternalFormat
== GL_RGB
&&
1151 srcFormat
== GL_RGB
&&
1152 srcType
== GL_UNSIGNED_BYTE
&&
1154 /* do optimized tex store */
1155 const GLint srcRowStride
=
1156 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1157 const GLubyte
*src
= (const GLubyte
*)
1158 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1159 srcFormat
, srcType
, 0, 0, 0);
1160 GLubyte
*dst
= dstSlices
[0];
1162 for (row
= 0; row
< srcHeight
; row
++) {
1163 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1164 GLushort
*dstUS
= (GLushort
*) dst
;
1165 /* check for byteswapped format */
1166 if (dstFormat
== MESA_FORMAT_B5G6R5_UNORM
) {
1167 for (col
= 0; col
< srcWidth
; col
++) {
1168 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1173 for (col
= 0; col
< srcWidth
; col
++) {
1174 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1178 dst
+= dstRowStride
;
1179 src
+= srcRowStride
;
1183 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1184 dstFormat
, dstRowStride
, dstSlices
,
1185 srcWidth
, srcHeight
, srcDepth
,
1186 srcFormat
, srcType
, srcAddr
, srcPacking
);
1193 * Store a texture in MESA_FORMAT_A8B8G8R8_UNORM or MESA_FORMAT_R8G8B8A8_UNORM.
1196 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1198 const GLboolean littleEndian
= _mesa_little_endian();
1200 ASSERT(dstFormat
== MESA_FORMAT_A8B8G8R8_UNORM
||
1201 dstFormat
== MESA_FORMAT_R8G8B8A8_UNORM
||
1202 dstFormat
== MESA_FORMAT_X8B8G8R8_UNORM
||
1203 dstFormat
== MESA_FORMAT_R8G8B8X8_UNORM
);
1204 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1206 if (!ctx
->_ImageTransferState
&&
1207 (srcType
== GL_UNSIGNED_BYTE
||
1208 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1209 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1210 can_swizzle(baseInternalFormat
) &&
1211 can_swizzle(srcFormat
)) {
1215 /* dstmap - how to swizzle from RGBA to dst format:
1217 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_A8B8G8R8_UNORM
||
1218 dstFormat
== MESA_FORMAT_X8B8G8R8_UNORM
)) ||
1219 (!littleEndian
&& (dstFormat
== MESA_FORMAT_R8G8B8A8_UNORM
||
1220 dstFormat
== MESA_FORMAT_R8G8B8X8_UNORM
))) {
1233 _mesa_swizzle_ubyte_image(ctx
, dims
,
1238 dstRowStride
, dstSlices
,
1239 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1243 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1244 dstFormat
, dstRowStride
, dstSlices
,
1245 srcWidth
, srcHeight
, srcDepth
,
1246 srcFormat
, srcType
, srcAddr
, srcPacking
);
1253 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1255 const GLboolean littleEndian
= _mesa_little_endian();
1257 ASSERT(dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
||
1258 dstFormat
== MESA_FORMAT_A8R8G8B8_UNORM
||
1259 dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
||
1260 dstFormat
== MESA_FORMAT_X8R8G8B8_UNORM
);
1261 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1263 if (!ctx
->_ImageTransferState
&&
1264 !srcPacking
->SwapBytes
&&
1265 (dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
||
1266 dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
) &&
1267 srcFormat
== GL_RGB
&&
1268 (baseInternalFormat
== GL_RGBA
||
1269 baseInternalFormat
== GL_RGB
) &&
1270 srcType
== GL_UNSIGNED_BYTE
) {
1272 for (img
= 0; img
< srcDepth
; img
++) {
1273 const GLint srcRowStride
=
1274 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1275 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1276 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1277 GLubyte
*dstRow
= dstSlices
[img
];
1278 for (row
= 0; row
< srcHeight
; row
++) {
1279 GLuint
*d4
= (GLuint
*) dstRow
;
1280 for (col
= 0; col
< srcWidth
; col
++) {
1281 d4
[col
] = PACK_COLOR_8888(0xff,
1282 srcRow
[col
* 3 + RCOMP
],
1283 srcRow
[col
* 3 + GCOMP
],
1284 srcRow
[col
* 3 + BCOMP
]);
1286 dstRow
+= dstRowStride
;
1287 srcRow
+= srcRowStride
;
1291 else if (!ctx
->_ImageTransferState
&&
1292 !srcPacking
->SwapBytes
&&
1293 dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
&&
1294 srcFormat
== GL_LUMINANCE_ALPHA
&&
1295 baseInternalFormat
== GL_RGBA
&&
1296 srcType
== GL_UNSIGNED_BYTE
) {
1297 /* special case of storing LA -> ARGB8888 */
1299 const GLint srcRowStride
=
1300 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1301 for (img
= 0; img
< srcDepth
; img
++) {
1302 const GLubyte
*srcRow
= (const GLubyte
*)
1303 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
,
1304 srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1305 GLubyte
*dstRow
= dstSlices
[img
];
1306 for (row
= 0; row
< srcHeight
; row
++) {
1307 GLuint
*d4
= (GLuint
*) dstRow
;
1308 for (col
= 0; col
< srcWidth
; col
++) {
1309 GLubyte l
= srcRow
[col
* 2 + 0], a
= srcRow
[col
* 2 + 1];
1310 d4
[col
] = PACK_COLOR_8888(a
, l
, l
, l
);
1312 dstRow
+= dstRowStride
;
1313 srcRow
+= srcRowStride
;
1317 else if (!ctx
->_ImageTransferState
&&
1318 !srcPacking
->SwapBytes
&&
1319 dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
&&
1320 srcFormat
== GL_RGBA
&&
1321 baseInternalFormat
== GL_RGBA
&&
1322 srcType
== GL_UNSIGNED_BYTE
) {
1323 /* same as above case, but src data has alpha too */
1324 GLint img
, row
, col
;
1325 /* For some reason, streaming copies to write-combined regions
1326 * are extremely sensitive to the characteristics of how the
1327 * source data is retrieved. By reordering the source reads to
1328 * be in-order, the speed of this operation increases by half.
1329 * Strangely the same isn't required for the RGB path, above.
1331 for (img
= 0; img
< srcDepth
; img
++) {
1332 const GLint srcRowStride
=
1333 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1334 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1335 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1336 GLubyte
*dstRow
= dstSlices
[img
];
1337 for (row
= 0; row
< srcHeight
; row
++) {
1338 GLuint
*d4
= (GLuint
*) dstRow
;
1339 for (col
= 0; col
< srcWidth
; col
++) {
1340 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1341 srcRow
[col
* 4 + RCOMP
],
1342 srcRow
[col
* 4 + GCOMP
],
1343 srcRow
[col
* 4 + BCOMP
]);
1345 dstRow
+= dstRowStride
;
1346 srcRow
+= srcRowStride
;
1350 else if (!ctx
->_ImageTransferState
&&
1351 (srcType
== GL_UNSIGNED_BYTE
||
1352 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1353 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1354 can_swizzle(baseInternalFormat
) &&
1355 can_swizzle(srcFormat
)) {
1359 /* dstmap - how to swizzle from RGBA to dst format:
1361 if ((littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
) ||
1362 (littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
) ||
1363 (!littleEndian
&& dstFormat
== MESA_FORMAT_A8R8G8B8_UNORM
) ||
1364 (!littleEndian
&& dstFormat
== MESA_FORMAT_X8R8G8B8_UNORM
)) {
1365 dstmap
[3] = 3; /* alpha */
1366 dstmap
[2] = 0; /* red */
1367 dstmap
[1] = 1; /* green */
1368 dstmap
[0] = 2; /* blue */
1371 assert((littleEndian
&& dstFormat
== MESA_FORMAT_A8R8G8B8_UNORM
) ||
1372 (!littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
) ||
1373 (littleEndian
&& dstFormat
== MESA_FORMAT_X8R8G8B8_UNORM
) ||
1374 (!littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
));
1381 _mesa_swizzle_ubyte_image(ctx
, dims
,
1388 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1392 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1393 dstFormat
, dstRowStride
, dstSlices
,
1394 srcWidth
, srcHeight
, srcDepth
,
1395 srcFormat
, srcType
, srcAddr
, srcPacking
);
1402 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1404 ASSERT(dstFormat
== MESA_FORMAT_BGR_UNORM8
);
1405 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1407 if (!ctx
->_ImageTransferState
&&
1408 !srcPacking
->SwapBytes
&&
1409 srcFormat
== GL_RGBA
&&
1410 srcType
== GL_UNSIGNED_BYTE
) {
1411 /* extract RGB from RGBA */
1412 GLint img
, row
, col
;
1413 for (img
= 0; img
< srcDepth
; img
++) {
1414 const GLint srcRowStride
=
1415 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1416 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1417 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1418 GLubyte
*dstRow
= dstSlices
[img
];
1419 for (row
= 0; row
< srcHeight
; row
++) {
1420 for (col
= 0; col
< srcWidth
; col
++) {
1421 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1422 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1423 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1425 dstRow
+= dstRowStride
;
1426 srcRow
+= srcRowStride
;
1430 else if (!ctx
->_ImageTransferState
&&
1431 srcType
== GL_UNSIGNED_BYTE
&&
1432 can_swizzle(baseInternalFormat
) &&
1433 can_swizzle(srcFormat
)) {
1437 /* dstmap - how to swizzle from RGBA to dst format:
1442 dstmap
[3] = ONE
; /* ? */
1444 _mesa_swizzle_ubyte_image(ctx
, dims
,
1449 dstRowStride
, dstSlices
,
1450 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1454 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1455 dstFormat
, dstRowStride
, dstSlices
,
1456 srcWidth
, srcHeight
, srcDepth
,
1457 srcFormat
, srcType
, srcAddr
, srcPacking
);
1464 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1466 ASSERT(dstFormat
== MESA_FORMAT_RGB_UNORM8
);
1467 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1469 if (!ctx
->_ImageTransferState
&&
1470 !srcPacking
->SwapBytes
&&
1471 srcFormat
== GL_RGBA
&&
1472 srcType
== GL_UNSIGNED_BYTE
) {
1473 /* extract BGR from RGBA */
1475 for (img
= 0; img
< srcDepth
; img
++) {
1476 const GLint srcRowStride
=
1477 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1478 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1479 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1480 GLubyte
*dstRow
= dstSlices
[img
];
1481 for (row
= 0; row
< srcHeight
; row
++) {
1482 for (col
= 0; col
< srcWidth
; col
++) {
1483 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1484 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1485 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1487 dstRow
+= dstRowStride
;
1488 srcRow
+= srcRowStride
;
1492 else if (!ctx
->_ImageTransferState
&&
1493 srcType
== GL_UNSIGNED_BYTE
&&
1494 can_swizzle(baseInternalFormat
) &&
1495 can_swizzle(srcFormat
)) {
1499 /* dstmap - how to swizzle from RGBA to dst format:
1504 dstmap
[3] = ONE
; /* ? */
1506 _mesa_swizzle_ubyte_image(ctx
, dims
,
1511 dstRowStride
, dstSlices
,
1512 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1516 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1517 dstFormat
, dstRowStride
, dstSlices
,
1518 srcWidth
, srcHeight
, srcDepth
,
1519 srcFormat
, srcType
, srcAddr
, srcPacking
);
1526 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1528 ASSERT(dstFormat
== MESA_FORMAT_B10G10R10A2_UNORM
||
1529 dstFormat
== MESA_FORMAT_B10G10R10X2_UNORM
);
1530 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1534 /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0
1535 * if the internal format is RGB. */
1536 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1539 srcWidth
, srcHeight
, srcDepth
,
1540 srcFormat
, srcType
, srcAddr
,
1542 ctx
->_ImageTransferState
);
1543 const GLfloat
*src
= tempImage
;
1544 GLint img
, row
, col
;
1547 for (img
= 0; img
< srcDepth
; img
++) {
1548 GLubyte
*dstRow
= dstSlices
[img
];
1549 if (baseInternalFormat
== GL_RGBA
|| baseInternalFormat
== GL_RGB
) {
1550 for (row
= 0; row
< srcHeight
; row
++) {
1551 GLuint
*dstUI
= (GLuint
*) dstRow
;
1552 for (col
= 0; col
< srcWidth
; col
++) {
1555 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1556 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1557 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1558 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1559 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1562 dstRow
+= dstRowStride
;
1568 free((void *) tempImage
);
1575 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1578 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1580 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1582 ASSERT(dstFormat
== MESA_FORMAT_L4A4_UNORM
);
1583 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1587 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1590 srcWidth
, srcHeight
, srcDepth
,
1591 srcFormat
, srcType
, srcAddr
,
1593 const GLubyte
*src
= tempImage
;
1594 GLint img
, row
, col
;
1597 for (img
= 0; img
< srcDepth
; img
++) {
1598 GLubyte
*dstRow
= dstSlices
[img
];
1599 for (row
= 0; row
< srcHeight
; row
++) {
1600 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1601 for (col
= 0; col
< srcWidth
; col
++) {
1602 /* src[0] is luminance, src[1] is alpha */
1603 dstUS
[col
] = PACK_COLOR_44( src
[1],
1607 dstRow
+= dstRowStride
;
1610 free((void *) tempImage
);
1617 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1620 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1622 const GLboolean littleEndian
= _mesa_little_endian();
1623 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1625 ASSERT(dstFormat
== MESA_FORMAT_L8A8_UNORM
||
1626 dstFormat
== MESA_FORMAT_A8L8_UNORM
||
1627 dstFormat
== MESA_FORMAT_R8G8_UNORM
||
1628 dstFormat
== MESA_FORMAT_G8R8_UNORM
);
1629 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1631 if (!ctx
->_ImageTransferState
&&
1633 srcType
== GL_UNSIGNED_BYTE
&&
1634 can_swizzle(baseInternalFormat
) &&
1635 can_swizzle(srcFormat
)) {
1638 /* dstmap - how to swizzle from RGBA to dst format:
1640 if (dstFormat
== MESA_FORMAT_L8A8_UNORM
|| dstFormat
== MESA_FORMAT_A8L8_UNORM
) {
1641 if ((littleEndian
&& dstFormat
== MESA_FORMAT_L8A8_UNORM
) ||
1642 (!littleEndian
&& dstFormat
== MESA_FORMAT_A8L8_UNORM
)) {
1652 if ((littleEndian
&& dstFormat
== MESA_FORMAT_R8G8_UNORM
) ||
1653 (!littleEndian
&& dstFormat
== MESA_FORMAT_G8R8_UNORM
)) {
1662 dstmap
[2] = ZERO
; /* ? */
1663 dstmap
[3] = ONE
; /* ? */
1665 _mesa_swizzle_ubyte_image(ctx
, dims
,
1670 dstRowStride
, dstSlices
,
1671 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1676 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1679 srcWidth
, srcHeight
, srcDepth
,
1680 srcFormat
, srcType
, srcAddr
,
1682 const GLubyte
*src
= tempImage
;
1683 GLint img
, row
, col
;
1686 for (img
= 0; img
< srcDepth
; img
++) {
1687 GLubyte
*dstRow
= dstSlices
[img
];
1688 for (row
= 0; row
< srcHeight
; row
++) {
1689 GLushort
*dstUS
= (GLushort
*) dstRow
;
1690 if (dstFormat
== MESA_FORMAT_L8A8_UNORM
||
1691 dstFormat
== MESA_FORMAT_R8G8_UNORM
) {
1692 for (col
= 0; col
< srcWidth
; col
++) {
1693 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1694 dstUS
[col
] = PACK_COLOR_88( src
[1],
1700 for (col
= 0; col
< srcWidth
; col
++) {
1701 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1702 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
1707 dstRow
+= dstRowStride
;
1710 free((void *) tempImage
);
1717 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
1720 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
1722 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1724 ASSERT(dstFormat
== MESA_FORMAT_L16A16_UNORM
||
1725 dstFormat
== MESA_FORMAT_A16L16_UNORM
||
1726 dstFormat
== MESA_FORMAT_R16G16_UNORM
||
1727 dstFormat
== MESA_FORMAT_G16R16_UNORM
);
1728 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1732 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1735 srcWidth
, srcHeight
, srcDepth
,
1736 srcFormat
, srcType
, srcAddr
,
1738 ctx
->_ImageTransferState
);
1739 const GLfloat
*src
= tempImage
;
1740 GLint img
, row
, col
;
1743 for (img
= 0; img
< srcDepth
; img
++) {
1744 GLubyte
*dstRow
= dstSlices
[img
];
1745 for (row
= 0; row
< srcHeight
; row
++) {
1746 GLuint
*dstUI
= (GLuint
*) dstRow
;
1747 if (dstFormat
== MESA_FORMAT_L16A16_UNORM
||
1748 dstFormat
== MESA_FORMAT_R16G16_UNORM
) {
1749 for (col
= 0; col
< srcWidth
; col
++) {
1752 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1753 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1754 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
1759 for (col
= 0; col
< srcWidth
; col
++) {
1762 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1763 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1764 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
1768 dstRow
+= dstRowStride
;
1771 free((void *) tempImage
);
1777 /* Texstore for R16, A16, L16, I16. */
1779 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
1781 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1783 ASSERT(dstFormat
== MESA_FORMAT_R_UNORM16
||
1784 dstFormat
== MESA_FORMAT_A_UNORM16
||
1785 dstFormat
== MESA_FORMAT_L_UNORM16
||
1786 dstFormat
== MESA_FORMAT_I_UNORM16
);
1787 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1791 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1794 srcWidth
, srcHeight
, srcDepth
,
1795 srcFormat
, srcType
, srcAddr
,
1797 ctx
->_ImageTransferState
);
1798 const GLfloat
*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 for (col
= 0; col
< srcWidth
; col
++) {
1809 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
1813 dstRow
+= dstRowStride
;
1816 free((void *) tempImage
);
1823 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
1825 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UNORM16
||
1826 dstFormat
== MESA_FORMAT_RGBX_UNORM16
);
1827 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
1831 /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0
1832 * if the internal format is RGB. */
1833 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1836 srcWidth
, srcHeight
, srcDepth
,
1837 srcFormat
, srcType
, srcAddr
,
1839 ctx
->_ImageTransferState
);
1840 const GLfloat
*src
= tempImage
;
1841 GLint img
, row
, col
;
1846 for (img
= 0; img
< srcDepth
; img
++) {
1847 GLubyte
*dstRow
= dstSlices
[img
];
1848 for (row
= 0; row
< srcHeight
; row
++) {
1849 GLushort
*dstUS
= (GLushort
*) dstRow
;
1850 for (col
= 0; col
< srcWidth
; col
++) {
1851 GLushort r
, g
, b
, a
;
1853 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
1854 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
1855 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
1856 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
1863 dstRow
+= dstRowStride
;
1866 free((void *) tempImage
);
1873 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
1875 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1877 ASSERT(dstFormat
== MESA_FORMAT_RGB_SNORM16
||
1878 dstFormat
== MESA_FORMAT_RGBA_SNORM16
||
1879 dstFormat
== MESA_FORMAT_RGBX_SNORM16
);
1883 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1886 srcWidth
, srcHeight
, srcDepth
,
1887 srcFormat
, srcType
, srcAddr
,
1889 ctx
->_ImageTransferState
);
1890 const GLfloat
*src
= tempImage
;
1891 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
1892 GLint img
, row
, col
;
1897 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
1898 * 3 or 4 components/pixel here.
1900 for (img
= 0; img
< srcDepth
; img
++) {
1901 GLubyte
*dstRow
= dstSlices
[img
];
1902 for (row
= 0; row
< srcHeight
; row
++) {
1903 GLshort
*dstRowS
= (GLshort
*) dstRow
;
1904 if (dstFormat
== MESA_FORMAT_RGBA_SNORM16
) {
1905 for (col
= 0; col
< srcWidth
; col
++) {
1907 for (c
= 0; c
< comps
; c
++) {
1909 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
1910 dstRowS
[col
* comps
+ c
] = p
;
1913 dstRow
+= dstRowStride
;
1914 src
+= 4 * srcWidth
;
1916 else if (dstFormat
== MESA_FORMAT_RGBX_SNORM16
) {
1917 for (col
= 0; col
< srcWidth
; col
++) {
1920 for (c
= 0; c
< 3; c
++) {
1922 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
1923 dstRowS
[col
* comps
+ c
] = p
;
1925 dstRowS
[col
* comps
+ 3] = 32767;
1927 dstRow
+= dstRowStride
;
1928 src
+= 3 * srcWidth
;
1931 for (col
= 0; col
< srcWidth
; col
++) {
1933 for (c
= 0; c
< comps
; c
++) {
1935 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
1936 dstRowS
[col
* comps
+ c
] = p
;
1939 dstRow
+= dstRowStride
;
1940 src
+= 3 * srcWidth
;
1944 free((void *) tempImage
);
1951 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
1954 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
1956 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1958 ASSERT(dstFormat
== MESA_FORMAT_A_UNORM8
||
1959 dstFormat
== MESA_FORMAT_L_UNORM8
||
1960 dstFormat
== MESA_FORMAT_I_UNORM8
||
1961 dstFormat
== MESA_FORMAT_R_UNORM8
);
1962 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1964 if (!ctx
->_ImageTransferState
&&
1965 srcType
== GL_UNSIGNED_BYTE
&&
1966 can_swizzle(baseInternalFormat
) &&
1967 can_swizzle(srcFormat
)) {
1970 /* dstmap - how to swizzle from RGBA to dst format:
1972 if (dstFormat
== MESA_FORMAT_A_UNORM8
) {
1978 dstmap
[1] = ZERO
; /* ? */
1979 dstmap
[2] = ZERO
; /* ? */
1980 dstmap
[3] = ONE
; /* ? */
1982 _mesa_swizzle_ubyte_image(ctx
, dims
,
1987 dstRowStride
, dstSlices
,
1988 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1993 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1996 srcWidth
, srcHeight
, srcDepth
,
1997 srcFormat
, srcType
, srcAddr
,
1999 const GLubyte
*src
= tempImage
;
2000 GLint img
, row
, col
;
2003 for (img
= 0; img
< srcDepth
; img
++) {
2004 GLubyte
*dstRow
= dstSlices
[img
];
2005 for (row
= 0; row
< srcHeight
; row
++) {
2006 for (col
= 0; col
< srcWidth
; col
++) {
2007 dstRow
[col
] = src
[col
];
2009 dstRow
+= dstRowStride
;
2013 free((void *) tempImage
);
2021 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2024 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2026 const GLboolean littleEndian
= _mesa_little_endian();
2028 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2030 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2031 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2032 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2033 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2034 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2035 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2036 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2037 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2039 /* always just memcpy since no pixel transfer ops apply */
2040 memcpy_texture(ctx
, dims
,
2042 dstRowStride
, dstSlices
,
2043 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2044 srcAddr
, srcPacking
);
2046 /* Check if we need byte swapping */
2047 /* XXX the logic here _might_ be wrong */
2048 if (srcPacking
->SwapBytes
^
2049 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2050 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2053 for (img
= 0; img
< srcDepth
; img
++) {
2054 GLubyte
*dstRow
= dstSlices
[img
];
2055 for (row
= 0; row
< srcHeight
; row
++) {
2056 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2057 dstRow
+= dstRowStride
;
2066 * Store a texture in a signed normalized 8-bit format.
2069 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2071 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2073 ASSERT(dstFormat
== MESA_FORMAT_A_SNORM8
||
2074 dstFormat
== MESA_FORMAT_L_SNORM8
||
2075 dstFormat
== MESA_FORMAT_I_SNORM8
||
2076 dstFormat
== MESA_FORMAT_R_SNORM8
);
2077 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2081 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2084 srcWidth
, srcHeight
, srcDepth
,
2085 srcFormat
, srcType
, srcAddr
,
2087 ctx
->_ImageTransferState
);
2088 const GLfloat
*src
= tempImage
;
2089 GLint img
, row
, col
;
2092 for (img
= 0; img
< srcDepth
; img
++) {
2093 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2094 for (row
= 0; row
< srcHeight
; row
++) {
2095 for (col
= 0; col
< srcWidth
; col
++) {
2096 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2098 dstRow
+= dstRowStride
;
2102 free((void *) tempImage
);
2109 * Store a texture in a signed normalized two-channel 16-bit format.
2112 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2114 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2116 ASSERT(dstFormat
== MESA_FORMAT_L8A8_SNORM
||
2117 dstFormat
== MESA_FORMAT_G8R8_SNORM
||
2118 dstFormat
== MESA_FORMAT_R8G8_SNORM
);
2119 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2123 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2126 srcWidth
, srcHeight
, srcDepth
,
2127 srcFormat
, srcType
, srcAddr
,
2129 ctx
->_ImageTransferState
);
2130 const GLfloat
*src
= tempImage
;
2131 GLint img
, row
, col
;
2134 for (img
= 0; img
< srcDepth
; img
++) {
2135 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2136 for (row
= 0; row
< srcHeight
; row
++) {
2137 GLushort
*dst
= (GLushort
*) dstRow
;
2139 if (dstFormat
== MESA_FORMAT_L8A8_SNORM
||
2140 dstFormat
== MESA_FORMAT_R8G8_SNORM
) {
2141 for (col
= 0; col
< srcWidth
; col
++) {
2142 GLubyte l
= FLOAT_TO_BYTE_TEX(src
[0]);
2143 GLubyte a
= FLOAT_TO_BYTE_TEX(src
[1]);
2145 dst
[col
] = PACK_COLOR_88_REV(l
, a
);
2149 for (col
= 0; col
< srcWidth
; col
++) {
2150 GLubyte l
= FLOAT_TO_BYTE_TEX(src
[0]);
2151 GLubyte a
= FLOAT_TO_BYTE_TEX(src
[1]);
2153 dst
[col
] = PACK_COLOR_88(l
, a
);
2158 dstRow
+= dstRowStride
;
2161 free((void *) tempImage
);
2166 /* Texstore for signed R16, A16, L16, I16. */
2168 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2170 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2172 ASSERT(dstFormat
== MESA_FORMAT_R_SNORM16
||
2173 dstFormat
== MESA_FORMAT_A_SNORM16
||
2174 dstFormat
== MESA_FORMAT_L_SNORM16
||
2175 dstFormat
== MESA_FORMAT_I_SNORM16
);
2176 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2180 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2183 srcWidth
, srcHeight
, srcDepth
,
2184 srcFormat
, srcType
, srcAddr
,
2186 ctx
->_ImageTransferState
);
2187 const GLfloat
*src
= tempImage
;
2188 GLint img
, row
, col
;
2191 for (img
= 0; img
< srcDepth
; img
++) {
2192 GLubyte
*dstRow
= dstSlices
[img
];
2193 for (row
= 0; row
< srcHeight
; row
++) {
2194 GLshort
*dstUS
= (GLshort
*) dstRow
;
2195 for (col
= 0; col
< srcWidth
; col
++) {
2198 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2202 dstRow
+= dstRowStride
;
2205 free((void *) tempImage
);
2211 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2214 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2216 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2218 ASSERT(dstFormat
== MESA_FORMAT_LA_SNORM16
||
2219 dstFormat
== MESA_FORMAT_G16R16_SNORM
||
2220 dstFormat
== MESA_FORMAT_R16G16_SNORM
);
2221 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2225 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2228 srcWidth
, srcHeight
, srcDepth
,
2229 srcFormat
, srcType
, srcAddr
,
2231 ctx
->_ImageTransferState
);
2232 const GLfloat
*src
= tempImage
;
2233 GLint img
, row
, col
;
2236 for (img
= 0; img
< srcDepth
; img
++) {
2237 GLubyte
*dstRow
= dstSlices
[img
];
2238 for (row
= 0; row
< srcHeight
; row
++) {
2239 GLuint
*dst
= (GLuint
*) dstRow
;
2241 if (dstFormat
== MESA_FORMAT_LA_SNORM16
||
2242 dstFormat
== MESA_FORMAT_R16G16_SNORM
) {
2243 for (col
= 0; col
< srcWidth
; col
++) {
2246 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2247 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2248 dst
[col
] = PACK_COLOR_1616_REV(l
, a
);
2252 for (col
= 0; col
< srcWidth
; col
++) {
2255 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2256 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2257 dst
[col
] = PACK_COLOR_1616_REV(l
, a
);
2262 dstRow
+= dstRowStride
;
2265 free((void *) tempImage
);
2271 * Store a texture in MESA_FORMAT_X8B8G8R8_SNORM or
2272 * MESA_FORMAT_R8G8B8X8_SNORM.
2275 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2277 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2279 ASSERT(dstFormat
== MESA_FORMAT_X8B8G8R8_SNORM
||
2280 dstFormat
== MESA_FORMAT_R8G8B8X8_SNORM
);
2281 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2285 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2288 srcWidth
, srcHeight
, srcDepth
,
2289 srcFormat
, srcType
, srcAddr
,
2291 ctx
->_ImageTransferState
);
2292 const GLfloat
*srcRow
= tempImage
;
2293 GLint img
, row
, col
;
2296 for (img
= 0; img
< srcDepth
; img
++) {
2297 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2298 for (row
= 0; row
< srcHeight
; row
++) {
2299 GLbyte
*dst
= dstRow
;
2300 if (dstFormat
== MESA_FORMAT_X8B8G8R8_SNORM
) {
2301 for (col
= 0; col
< srcWidth
; col
++) {
2302 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2303 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2304 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2311 for (col
= 0; col
< srcWidth
; col
++) {
2312 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2313 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2314 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2320 dstRow
+= dstRowStride
;
2323 free((void *) tempImage
);
2331 * Store a texture in MESA_FORMAT_A8B8G8R8_SNORM or
2332 * MESA_FORMAT_R8G8B8A8_SNORM
2335 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2337 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2339 ASSERT(dstFormat
== MESA_FORMAT_A8B8G8R8_SNORM
||
2340 dstFormat
== MESA_FORMAT_R8G8B8A8_SNORM
);
2341 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2345 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2348 srcWidth
, srcHeight
, srcDepth
,
2349 srcFormat
, srcType
, srcAddr
,
2351 ctx
->_ImageTransferState
);
2352 const GLfloat
*srcRow
= tempImage
;
2353 GLint img
, row
, col
;
2356 for (img
= 0; img
< srcDepth
; img
++) {
2357 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2358 for (row
= 0; row
< srcHeight
; row
++) {
2359 GLbyte
*dst
= dstRow
;
2360 if (dstFormat
== MESA_FORMAT_A8B8G8R8_SNORM
) {
2361 for (col
= 0; col
< srcWidth
; col
++) {
2362 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2363 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2364 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2365 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2371 for (col
= 0; col
< srcWidth
; col
++) {
2372 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2373 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2374 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2375 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2380 dstRow
+= dstRowStride
;
2383 free((void *) tempImage
);
2390 * Store a combined depth/stencil texture image.
2393 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2395 const GLuint depthScale
= 0xffffff;
2396 const GLint srcRowStride
2397 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2399 GLuint
*depth
= malloc(srcWidth
* sizeof(GLuint
));
2400 GLubyte
*stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2402 ASSERT(dstFormat
== MESA_FORMAT_S8_UINT_Z24_UNORM
);
2403 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2404 srcFormat
== GL_DEPTH_COMPONENT
||
2405 srcFormat
== GL_STENCIL_INDEX
);
2406 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2407 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2408 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
2410 if (!depth
|| !stencil
) {
2416 /* In case we only upload depth we need to preserve the stencil */
2417 for (img
= 0; img
< srcDepth
; img
++) {
2418 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2420 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2421 srcWidth
, srcHeight
,
2424 for (row
= 0; row
< srcHeight
; row
++) {
2426 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2428 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2429 keepstencil
= GL_TRUE
;
2431 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2432 keepdepth
= GL_TRUE
;
2435 if (keepdepth
== GL_FALSE
)
2436 /* the 24 depth bits will be in the low position: */
2437 _mesa_unpack_depth_span(ctx
, srcWidth
,
2438 GL_UNSIGNED_INT
, /* dst type */
2439 keepstencil
? depth
: dstRow
, /* dst addr */
2441 srcType
, src
, srcPacking
);
2443 if (keepstencil
== GL_FALSE
)
2444 /* get the 8-bit stencil values */
2445 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2446 GL_UNSIGNED_BYTE
, /* dst type */
2447 stencil
, /* dst addr */
2448 srcType
, src
, srcPacking
,
2449 ctx
->_ImageTransferState
);
2451 for (i
= 0; i
< srcWidth
; i
++) {
2453 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2455 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2457 src
+= srcRowStride
;
2458 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2469 * Store a combined depth/stencil texture image.
2472 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2474 const GLuint depthScale
= 0xffffff;
2475 const GLint srcRowStride
2476 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2481 ASSERT(dstFormat
== MESA_FORMAT_Z24_UNORM_S8_UINT
);
2482 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2483 srcFormat
== GL_DEPTH_COMPONENT
||
2484 srcFormat
== GL_STENCIL_INDEX
);
2485 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2486 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2487 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
2489 depth
= malloc(srcWidth
* sizeof(GLuint
));
2490 stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2492 if (!depth
|| !stencil
) {
2498 for (img
= 0; img
< srcDepth
; img
++) {
2499 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2501 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2502 srcWidth
, srcHeight
,
2505 for (row
= 0; row
< srcHeight
; row
++) {
2507 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2509 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2510 keepstencil
= GL_TRUE
;
2512 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2513 keepdepth
= GL_TRUE
;
2516 if (keepdepth
== GL_FALSE
)
2517 /* the 24 depth bits will be in the low position: */
2518 _mesa_unpack_depth_span(ctx
, srcWidth
,
2519 GL_UNSIGNED_INT
, /* dst type */
2520 keepstencil
? depth
: dstRow
, /* dst addr */
2522 srcType
, src
, srcPacking
);
2524 if (keepstencil
== GL_FALSE
)
2525 /* get the 8-bit stencil values */
2526 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2527 GL_UNSIGNED_BYTE
, /* dst type */
2528 stencil
, /* dst addr */
2529 srcType
, src
, srcPacking
,
2530 ctx
->_ImageTransferState
);
2532 /* merge stencil values into depth values */
2533 for (i
= 0; i
< srcWidth
; i
++) {
2535 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2537 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
2540 src
+= srcRowStride
;
2541 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2553 * Store simple 8-bit/value stencil texture data.
2556 _mesa_texstore_s8(TEXSTORE_PARAMS
)
2558 ASSERT(dstFormat
== MESA_FORMAT_S_UINT8
);
2559 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
2562 const GLint srcRowStride
2563 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2565 GLubyte
*stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2570 for (img
= 0; img
< srcDepth
; img
++) {
2571 GLubyte
*dstRow
= dstSlices
[img
];
2573 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2574 srcWidth
, srcHeight
,
2577 for (row
= 0; row
< srcHeight
; row
++) {
2580 /* get the 8-bit stencil values */
2581 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2582 GL_UNSIGNED_BYTE
, /* dst type */
2583 stencil
, /* dst addr */
2584 srcType
, src
, srcPacking
,
2585 ctx
->_ImageTransferState
);
2586 /* merge stencil values into depth values */
2587 for (i
= 0; i
< srcWidth
; i
++)
2588 dstRow
[i
] = stencil
[i
];
2590 src
+= srcRowStride
;
2591 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
2603 * Store an image in any of the formats:
2604 * _mesa_texformat_rgba_float32
2605 * _mesa_texformat_rgb_float32
2606 * _mesa_texformat_alpha_float32
2607 * _mesa_texformat_luminance_float32
2608 * _mesa_texformat_luminance_alpha_float32
2609 * _mesa_texformat_intensity_float32
2612 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2614 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2615 GLint components
= _mesa_components_in_format(baseFormat
);
2617 /* this forces alpha to 1 in _mesa_make_temp_float_image */
2618 if (dstFormat
== MESA_FORMAT_RGBX_FLOAT32
) {
2619 baseFormat
= GL_RGBA
;
2623 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2624 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2625 dstFormat
== MESA_FORMAT_A_FLOAT32
||
2626 dstFormat
== MESA_FORMAT_L_FLOAT32
||
2627 dstFormat
== MESA_FORMAT_LA_FLOAT32
||
2628 dstFormat
== MESA_FORMAT_I_FLOAT32
||
2629 dstFormat
== MESA_FORMAT_R_FLOAT32
||
2630 dstFormat
== MESA_FORMAT_RG_FLOAT32
||
2631 dstFormat
== MESA_FORMAT_RGBX_FLOAT32
);
2632 ASSERT(baseInternalFormat
== GL_RGBA
||
2633 baseInternalFormat
== GL_RGB
||
2634 baseInternalFormat
== GL_ALPHA
||
2635 baseInternalFormat
== GL_LUMINANCE
||
2636 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2637 baseInternalFormat
== GL_INTENSITY
||
2638 baseInternalFormat
== GL_RED
||
2639 baseInternalFormat
== GL_RG
);
2640 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
2644 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2647 srcWidth
, srcHeight
, srcDepth
,
2648 srcFormat
, srcType
, srcAddr
,
2650 ctx
->_ImageTransferState
);
2651 const GLfloat
*srcRow
= tempImage
;
2656 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2657 for (img
= 0; img
< srcDepth
; img
++) {
2658 GLubyte
*dstRow
= dstSlices
[img
];
2659 for (row
= 0; row
< srcHeight
; row
++) {
2660 memcpy(dstRow
, srcRow
, bytesPerRow
);
2661 dstRow
+= dstRowStride
;
2662 srcRow
+= srcWidth
* components
;
2666 free((void *) tempImage
);
2674 * As above, but store 16-bit floats.
2677 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2679 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2680 GLint components
= _mesa_components_in_format(baseFormat
);
2682 /* this forces alpha to 1 in _mesa_make_temp_float_image */
2683 if (dstFormat
== MESA_FORMAT_RGBX_FLOAT16
) {
2684 baseFormat
= GL_RGBA
;
2688 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2689 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2690 dstFormat
== MESA_FORMAT_A_FLOAT16
||
2691 dstFormat
== MESA_FORMAT_L_FLOAT16
||
2692 dstFormat
== MESA_FORMAT_LA_FLOAT16
||
2693 dstFormat
== MESA_FORMAT_I_FLOAT16
||
2694 dstFormat
== MESA_FORMAT_R_FLOAT16
||
2695 dstFormat
== MESA_FORMAT_RG_FLOAT16
||
2696 dstFormat
== MESA_FORMAT_RGBX_FLOAT16
);
2697 ASSERT(baseInternalFormat
== GL_RGBA
||
2698 baseInternalFormat
== GL_RGB
||
2699 baseInternalFormat
== GL_ALPHA
||
2700 baseInternalFormat
== GL_LUMINANCE
||
2701 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2702 baseInternalFormat
== GL_INTENSITY
||
2703 baseInternalFormat
== GL_RED
||
2704 baseInternalFormat
== GL_RG
);
2705 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
2709 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2712 srcWidth
, srcHeight
, srcDepth
,
2713 srcFormat
, srcType
, srcAddr
,
2715 ctx
->_ImageTransferState
);
2716 const GLfloat
*src
= tempImage
;
2720 for (img
= 0; img
< srcDepth
; img
++) {
2721 GLubyte
*dstRow
= dstSlices
[img
];
2722 for (row
= 0; row
< srcHeight
; row
++) {
2723 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2725 for (i
= 0; i
< srcWidth
* components
; i
++) {
2726 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2728 dstRow
+= dstRowStride
;
2729 src
+= srcWidth
* components
;
2733 free((void *) tempImage
);
2739 /* non-normalized, signed int8 */
2741 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
2743 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2744 GLint components
= _mesa_components_in_format(baseFormat
);
2746 /* this forces alpha to 1 in make_temp_uint_image */
2747 if (dstFormat
== MESA_FORMAT_RGBX_SINT8
) {
2748 baseFormat
= GL_RGBA
;
2752 ASSERT(dstFormat
== MESA_FORMAT_R_SINT8
||
2753 dstFormat
== MESA_FORMAT_RG_SINT8
||
2754 dstFormat
== MESA_FORMAT_RGB_SINT8
||
2755 dstFormat
== MESA_FORMAT_RGBA_SINT8
||
2756 dstFormat
== MESA_FORMAT_A_SINT8
||
2757 dstFormat
== MESA_FORMAT_I_SINT8
||
2758 dstFormat
== MESA_FORMAT_L_SINT8
||
2759 dstFormat
== MESA_FORMAT_LA_SINT8
||
2760 dstFormat
== MESA_FORMAT_RGBX_SINT8
);
2761 ASSERT(baseInternalFormat
== GL_RGBA
||
2762 baseInternalFormat
== GL_RGB
||
2763 baseInternalFormat
== GL_RG
||
2764 baseInternalFormat
== GL_RED
||
2765 baseInternalFormat
== GL_ALPHA
||
2766 baseInternalFormat
== GL_LUMINANCE
||
2767 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2768 baseInternalFormat
== GL_INTENSITY
);
2769 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
2773 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2776 srcWidth
, srcHeight
, srcDepth
,
2780 const GLuint
*src
= tempImage
;
2782 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2785 for (img
= 0; img
< srcDepth
; img
++) {
2786 GLubyte
*dstRow
= dstSlices
[img
];
2787 for (row
= 0; row
< srcHeight
; row
++) {
2788 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
2791 for (i
= 0; i
< srcWidth
* components
; i
++) {
2792 dstTexel
[i
] = (GLbyte
) MIN2(src
[i
], 0x7f);
2795 for (i
= 0; i
< srcWidth
* components
; i
++) {
2796 dstTexel
[i
] = (GLbyte
) CLAMP((GLint
) src
[i
], -0x80, 0x7f);
2799 dstRow
+= dstRowStride
;
2800 src
+= srcWidth
* components
;
2804 free((void *) tempImage
);
2810 /* non-normalized, signed int16 */
2812 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
2814 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2815 GLint components
= _mesa_components_in_format(baseFormat
);
2817 /* this forces alpha to 1 in make_temp_uint_image */
2818 if (dstFormat
== MESA_FORMAT_RGBX_SINT16
) {
2819 baseFormat
= GL_RGBA
;
2823 ASSERT(dstFormat
== MESA_FORMAT_R_SINT16
||
2824 dstFormat
== MESA_FORMAT_RG_SINT16
||
2825 dstFormat
== MESA_FORMAT_RGB_SINT16
||
2826 dstFormat
== MESA_FORMAT_RGBA_SINT16
||
2827 dstFormat
== MESA_FORMAT_A_SINT16
||
2828 dstFormat
== MESA_FORMAT_L_SINT16
||
2829 dstFormat
== MESA_FORMAT_I_SINT16
||
2830 dstFormat
== MESA_FORMAT_LA_SINT16
||
2831 dstFormat
== MESA_FORMAT_RGBX_SINT16
);
2832 ASSERT(baseInternalFormat
== GL_RGBA
||
2833 baseInternalFormat
== GL_RGB
||
2834 baseInternalFormat
== GL_RG
||
2835 baseInternalFormat
== GL_RED
||
2836 baseInternalFormat
== GL_ALPHA
||
2837 baseInternalFormat
== GL_LUMINANCE
||
2838 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2839 baseInternalFormat
== GL_INTENSITY
);
2840 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
2844 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2847 srcWidth
, srcHeight
, srcDepth
,
2851 const GLuint
*src
= tempImage
;
2853 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2856 for (img
= 0; img
< srcDepth
; img
++) {
2857 GLubyte
*dstRow
= dstSlices
[img
];
2858 for (row
= 0; row
< srcHeight
; row
++) {
2859 GLshort
*dstTexel
= (GLshort
*) dstRow
;
2862 for (i
= 0; i
< srcWidth
* components
; i
++) {
2863 dstTexel
[i
] = (GLshort
) MIN2(src
[i
], 0x7fff);
2866 for (i
= 0; i
< srcWidth
* components
; i
++) {
2867 dstTexel
[i
] = (GLshort
)CLAMP((GLint
) src
[i
], -0x8000, 0x7fff);
2870 dstRow
+= dstRowStride
;
2871 src
+= srcWidth
* components
;
2875 free((void *) tempImage
);
2881 /* non-normalized, signed int32 */
2883 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
2885 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2886 GLint components
= _mesa_components_in_format(baseFormat
);
2888 /* this forces alpha to 1 in make_temp_uint_image */
2889 if (dstFormat
== MESA_FORMAT_RGBX_SINT32
) {
2890 baseFormat
= GL_RGBA
;
2894 ASSERT(dstFormat
== MESA_FORMAT_R_SINT32
||
2895 dstFormat
== MESA_FORMAT_RG_SINT32
||
2896 dstFormat
== MESA_FORMAT_RGB_SINT32
||
2897 dstFormat
== MESA_FORMAT_RGBA_SINT32
||
2898 dstFormat
== MESA_FORMAT_A_SINT32
||
2899 dstFormat
== MESA_FORMAT_I_SINT32
||
2900 dstFormat
== MESA_FORMAT_L_SINT32
||
2901 dstFormat
== MESA_FORMAT_LA_SINT32
||
2902 dstFormat
== MESA_FORMAT_RGBX_SINT32
);
2903 ASSERT(baseInternalFormat
== GL_RGBA
||
2904 baseInternalFormat
== GL_RGB
||
2905 baseInternalFormat
== GL_RG
||
2906 baseInternalFormat
== GL_RED
||
2907 baseInternalFormat
== GL_ALPHA
||
2908 baseInternalFormat
== GL_LUMINANCE
||
2909 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2910 baseInternalFormat
== GL_INTENSITY
);
2911 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
2915 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2918 srcWidth
, srcHeight
, srcDepth
,
2922 const GLuint
*src
= tempImage
;
2924 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2927 for (img
= 0; img
< srcDepth
; img
++) {
2928 GLubyte
*dstRow
= dstSlices
[img
];
2929 for (row
= 0; row
< srcHeight
; row
++) {
2930 GLint
*dstTexel
= (GLint
*) dstRow
;
2933 for (i
= 0; i
< srcWidth
* components
; i
++) {
2934 dstTexel
[i
] = (GLint
) MIN2(src
[i
], 0x7fffffff);
2937 for (i
= 0; i
< srcWidth
* components
; i
++) {
2938 dstTexel
[i
] = (GLint
) src
[i
];
2941 dstRow
+= dstRowStride
;
2942 src
+= srcWidth
* components
;
2946 free((void *) tempImage
);
2952 /* non-normalized, unsigned int8 */
2954 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
2956 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2957 GLint components
= _mesa_components_in_format(baseFormat
);
2959 /* this forces alpha to 1 in make_temp_uint_image */
2960 if (dstFormat
== MESA_FORMAT_RGBX_UINT8
) {
2961 baseFormat
= GL_RGBA
;
2965 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
2966 dstFormat
== MESA_FORMAT_RG_UINT8
||
2967 dstFormat
== MESA_FORMAT_RGB_UINT8
||
2968 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
2969 dstFormat
== MESA_FORMAT_A_UINT8
||
2970 dstFormat
== MESA_FORMAT_I_UINT8
||
2971 dstFormat
== MESA_FORMAT_L_UINT8
||
2972 dstFormat
== MESA_FORMAT_LA_UINT8
||
2973 dstFormat
== MESA_FORMAT_RGBX_UINT8
);
2974 ASSERT(baseInternalFormat
== GL_RGBA
||
2975 baseInternalFormat
== GL_RGB
||
2976 baseInternalFormat
== GL_RG
||
2977 baseInternalFormat
== GL_RED
||
2978 baseInternalFormat
== GL_ALPHA
||
2979 baseInternalFormat
== GL_LUMINANCE
||
2980 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2981 baseInternalFormat
== GL_INTENSITY
);
2982 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
2986 const GLuint
*tempImage
=
2987 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
2988 srcWidth
, srcHeight
, srcDepth
,
2989 srcFormat
, srcType
, srcAddr
, srcPacking
);
2990 const GLuint
*src
= tempImage
;
2992 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2995 for (img
= 0; img
< srcDepth
; img
++) {
2996 GLubyte
*dstRow
= dstSlices
[img
];
2997 for (row
= 0; row
< srcHeight
; row
++) {
2998 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3001 for (i
= 0; i
< srcWidth
* components
; i
++) {
3002 dstTexel
[i
] = (GLubyte
) MIN2(src
[i
], 0xff);
3005 for (i
= 0; i
< srcWidth
* components
; i
++) {
3006 dstTexel
[i
] = (GLubyte
) CLAMP((GLint
) src
[i
], 0, 0xff);
3009 dstRow
+= dstRowStride
;
3010 src
+= srcWidth
* components
;
3014 free((void *) tempImage
);
3020 /* non-normalized, unsigned int16 */
3022 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3024 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3025 GLint components
= _mesa_components_in_format(baseFormat
);
3027 /* this forces alpha to 1 in make_temp_uint_image */
3028 if (dstFormat
== MESA_FORMAT_RGBX_UINT16
) {
3029 baseFormat
= GL_RGBA
;
3033 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3034 dstFormat
== MESA_FORMAT_RG_UINT16
||
3035 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3036 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3037 dstFormat
== MESA_FORMAT_A_UINT16
||
3038 dstFormat
== MESA_FORMAT_I_UINT16
||
3039 dstFormat
== MESA_FORMAT_L_UINT16
||
3040 dstFormat
== MESA_FORMAT_LA_UINT16
||
3041 dstFormat
== MESA_FORMAT_RGBX_UINT16
);
3042 ASSERT(baseInternalFormat
== GL_RGBA
||
3043 baseInternalFormat
== GL_RGB
||
3044 baseInternalFormat
== GL_RG
||
3045 baseInternalFormat
== GL_RED
||
3046 baseInternalFormat
== GL_ALPHA
||
3047 baseInternalFormat
== GL_LUMINANCE
||
3048 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3049 baseInternalFormat
== GL_INTENSITY
);
3050 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3054 const GLuint
*tempImage
=
3055 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3056 srcWidth
, srcHeight
, srcDepth
,
3057 srcFormat
, srcType
, srcAddr
, srcPacking
);
3058 const GLuint
*src
= tempImage
;
3060 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3063 for (img
= 0; img
< srcDepth
; img
++) {
3064 GLubyte
*dstRow
= dstSlices
[img
];
3065 for (row
= 0; row
< srcHeight
; row
++) {
3066 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3069 for (i
= 0; i
< srcWidth
* components
; i
++) {
3070 dstTexel
[i
] = (GLushort
) MIN2(src
[i
], 0xffff);
3073 for (i
= 0; i
< srcWidth
* components
; i
++) {
3074 dstTexel
[i
] = (GLushort
) CLAMP((GLint
) src
[i
], 0, 0xffff);
3077 dstRow
+= dstRowStride
;
3078 src
+= srcWidth
* components
;
3082 free((void *) tempImage
);
3088 /* non-normalized, unsigned int32 */
3090 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3092 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3093 GLint components
= _mesa_components_in_format(baseFormat
);
3095 /* this forces alpha to 1 in make_temp_uint_image */
3096 if (dstFormat
== MESA_FORMAT_RGBX_UINT32
) {
3097 baseFormat
= GL_RGBA
;
3101 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3102 dstFormat
== MESA_FORMAT_RG_UINT32
||
3103 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3104 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3105 dstFormat
== MESA_FORMAT_A_UINT32
||
3106 dstFormat
== MESA_FORMAT_I_UINT32
||
3107 dstFormat
== MESA_FORMAT_L_UINT32
||
3108 dstFormat
== MESA_FORMAT_LA_UINT32
||
3109 dstFormat
== MESA_FORMAT_RGBX_UINT32
);
3110 ASSERT(baseInternalFormat
== GL_RGBA
||
3111 baseInternalFormat
== GL_RGB
||
3112 baseInternalFormat
== GL_RG
||
3113 baseInternalFormat
== GL_RED
||
3114 baseInternalFormat
== GL_ALPHA
||
3115 baseInternalFormat
== GL_LUMINANCE
||
3116 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3117 baseInternalFormat
== GL_INTENSITY
);
3118 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3122 const GLuint
*tempImage
=
3123 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3124 srcWidth
, srcHeight
, srcDepth
,
3125 srcFormat
, srcType
, srcAddr
, srcPacking
);
3126 const GLuint
*src
= tempImage
;
3127 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3131 for (img
= 0; img
< srcDepth
; img
++) {
3132 GLubyte
*dstRow
= dstSlices
[img
];
3133 for (row
= 0; row
< srcHeight
; row
++) {
3134 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3137 for (i
= 0; i
< srcWidth
* components
; i
++) {
3138 dstTexel
[i
] = src
[i
];
3141 for (i
= 0; i
< srcWidth
* components
; i
++) {
3142 dstTexel
[i
] = MAX2((GLint
) src
[i
], 0);
3145 dstRow
+= dstRowStride
;
3146 src
+= srcWidth
* components
;
3150 free((void *) tempImage
);
3157 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3159 mesa_format newDstFormat
;
3162 ASSERT(dstFormat
== MESA_FORMAT_BGR_SRGB8
);
3164 /* reuse normal rgb texstore code */
3165 newDstFormat
= MESA_FORMAT_BGR_UNORM8
;
3167 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3169 dstRowStride
, dstSlices
,
3170 srcWidth
, srcHeight
, srcDepth
,
3172 srcAddr
, srcPacking
);
3178 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3180 mesa_format newDstFormat
;
3183 ASSERT(dstFormat
== MESA_FORMAT_A8B8G8R8_SRGB
||
3184 dstFormat
== MESA_FORMAT_R8G8B8X8_SRGB
||
3185 dstFormat
== MESA_FORMAT_R8G8B8A8_SRGB
);
3187 newDstFormat
= _mesa_get_srgb_format_linear(dstFormat
);
3189 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3191 dstRowStride
, dstSlices
,
3192 srcWidth
, srcHeight
, srcDepth
,
3194 srcAddr
, srcPacking
);
3200 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3202 mesa_format newDstFormat
;
3205 assert(dstFormat
== MESA_FORMAT_B8G8R8A8_SRGB
||
3206 dstFormat
== MESA_FORMAT_B8G8R8X8_SRGB
);
3208 newDstFormat
= _mesa_get_srgb_format_linear(dstFormat
);
3210 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3212 dstRowStride
, dstSlices
,
3213 srcWidth
, srcHeight
, srcDepth
,
3215 srcAddr
, srcPacking
);
3221 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3223 mesa_format newDstFormat
;
3226 ASSERT(dstFormat
== MESA_FORMAT_L_SRGB8
);
3228 newDstFormat
= MESA_FORMAT_L_UNORM8
;
3230 /* _mesa_textore_a8 handles luminance8 too */
3231 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3233 dstRowStride
, dstSlices
,
3234 srcWidth
, srcHeight
, srcDepth
,
3236 srcAddr
, srcPacking
);
3242 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3244 mesa_format newDstFormat
;
3247 ASSERT(dstFormat
== MESA_FORMAT_L8A8_SRGB
);
3249 /* reuse normal luminance/alpha texstore code */
3250 newDstFormat
= MESA_FORMAT_L8A8_UNORM
;
3252 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3254 dstRowStride
, dstSlices
,
3255 srcWidth
, srcHeight
, srcDepth
,
3257 srcAddr
, srcPacking
);
3262 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3264 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3266 ASSERT(dstFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
);
3267 ASSERT(baseInternalFormat
== GL_RGB
);
3271 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3274 srcWidth
, srcHeight
, srcDepth
,
3275 srcFormat
, srcType
, srcAddr
,
3277 ctx
->_ImageTransferState
);
3278 const GLfloat
*srcRow
= tempImage
;
3279 GLint img
, row
, col
;
3282 for (img
= 0; img
< srcDepth
; img
++) {
3283 GLubyte
*dstRow
= dstSlices
[img
];
3284 for (row
= 0; row
< srcHeight
; row
++) {
3285 GLuint
*dstUI
= (GLuint
*)dstRow
;
3286 for (col
= 0; col
< srcWidth
; col
++) {
3287 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3289 dstRow
+= dstRowStride
;
3290 srcRow
+= srcWidth
* 3;
3294 free((void *) tempImage
);
3300 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
3302 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3304 ASSERT(dstFormat
== MESA_FORMAT_R11G11B10_FLOAT
);
3305 ASSERT(baseInternalFormat
== GL_RGB
);
3309 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3312 srcWidth
, srcHeight
, srcDepth
,
3313 srcFormat
, srcType
, srcAddr
,
3315 ctx
->_ImageTransferState
);
3316 const GLfloat
*srcRow
= tempImage
;
3317 GLint img
, row
, col
;
3320 for (img
= 0; img
< srcDepth
; img
++) {
3321 GLubyte
*dstRow
= dstSlices
[img
];
3322 for (row
= 0; row
< srcHeight
; row
++) {
3323 GLuint
*dstUI
= (GLuint
*)dstRow
;
3324 for (col
= 0; col
< srcWidth
; col
++) {
3325 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
3327 dstRow
+= dstRowStride
;
3328 srcRow
+= srcWidth
* 3;
3332 free((void *) tempImage
);
3339 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
3342 const GLint srcRowStride
3343 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3346 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
);
3347 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
3348 srcFormat
== GL_DEPTH_COMPONENT
||
3349 srcFormat
== GL_STENCIL_INDEX
);
3350 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
3351 srcType
== GL_UNSIGNED_INT_24_8
||
3352 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
3354 /* In case we only upload depth we need to preserve the stencil */
3355 for (img
= 0; img
< srcDepth
; img
++) {
3356 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
3358 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3359 srcWidth
, srcHeight
,
3362 for (row
= 0; row
< srcHeight
; row
++) {
3363 /* The unpack functions with:
3364 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
3365 * only write their own dword, so the other dword (stencil
3366 * or depth) is preserved. */
3367 if (srcFormat
!= GL_STENCIL_INDEX
)
3368 _mesa_unpack_depth_span(ctx
, srcWidth
,
3369 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3370 dstRow
, /* dst addr */
3371 ~0U, srcType
, src
, srcPacking
);
3373 if (srcFormat
!= GL_DEPTH_COMPONENT
)
3374 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3375 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3376 dstRow
, /* dst addr */
3377 srcType
, src
, srcPacking
,
3378 ctx
->_ImageTransferState
);
3380 src
+= srcRowStride
;
3381 dstRow
+= dstRowStride
/ sizeof(uint64_t);
3388 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
3390 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3392 ASSERT(dstFormat
== MESA_FORMAT_B10G10R10A2_UINT
);
3393 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3397 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3400 srcWidth
, srcHeight
,
3401 srcDepth
, srcFormat
,
3404 const GLuint
*src
= tempImage
;
3405 GLint img
, row
, col
;
3406 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3409 for (img
= 0; img
< srcDepth
; img
++) {
3410 GLubyte
*dstRow
= dstSlices
[img
];
3412 for (row
= 0; row
< srcHeight
; row
++) {
3413 GLuint
*dstUI
= (GLuint
*) dstRow
;
3415 for (col
= 0; col
< srcWidth
; col
++) {
3417 r
= MIN2(src
[RCOMP
], 0x3ff);
3418 g
= MIN2(src
[GCOMP
], 0x3ff);
3419 b
= MIN2(src
[BCOMP
], 0x3ff);
3420 a
= MIN2(src
[ACOMP
], 0x003);
3421 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3425 for (col
= 0; col
< srcWidth
; col
++) {
3427 r
= CLAMP((GLint
) src
[RCOMP
], 0, 0x3ff);
3428 g
= CLAMP((GLint
) src
[GCOMP
], 0, 0x3ff);
3429 b
= CLAMP((GLint
) src
[BCOMP
], 0, 0x3ff);
3430 a
= CLAMP((GLint
) src
[ACOMP
], 0, 0x003);
3431 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3435 dstRow
+= dstRowStride
;
3438 free((void *) tempImage
);
3444 _mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS
)
3446 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3448 ASSERT(dstFormat
== MESA_FORMAT_R10G10B10A2_UINT
);
3449 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3453 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3456 srcWidth
, srcHeight
,
3457 srcDepth
, srcFormat
,
3460 const GLuint
*src
= tempImage
;
3461 GLint img
, row
, col
;
3462 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3465 for (img
= 0; img
< srcDepth
; img
++) {
3466 GLubyte
*dstRow
= dstSlices
[img
];
3468 for (row
= 0; row
< srcHeight
; row
++) {
3469 GLuint
*dstUI
= (GLuint
*) dstRow
;
3471 for (col
= 0; col
< srcWidth
; col
++) {
3473 r
= MIN2(src
[RCOMP
], 0x3ff);
3474 g
= MIN2(src
[GCOMP
], 0x3ff);
3475 b
= MIN2(src
[BCOMP
], 0x3ff);
3476 a
= MIN2(src
[ACOMP
], 0x003);
3477 dstUI
[col
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | (r
);
3481 for (col
= 0; col
< srcWidth
; col
++) {
3483 r
= CLAMP((GLint
) src
[RCOMP
], 0, 0x3ff);
3484 g
= CLAMP((GLint
) src
[GCOMP
], 0, 0x3ff);
3485 b
= CLAMP((GLint
) src
[BCOMP
], 0, 0x3ff);
3486 a
= CLAMP((GLint
) src
[ACOMP
], 0, 0x003);
3487 dstUI
[col
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | (r
);
3491 dstRow
+= dstRowStride
;
3494 free((void *) tempImage
);
3500 _mesa_texstore_abgr2101010(TEXSTORE_PARAMS
)
3502 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3504 ASSERT(dstFormat
== MESA_FORMAT_R10G10B10A2_UNORM
);
3505 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3509 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3512 srcWidth
, srcHeight
, srcDepth
,
3513 srcFormat
, srcType
, srcAddr
,
3515 ctx
->_ImageTransferState
);
3516 const GLfloat
*src
= tempImage
;
3517 GLint img
, row
, col
;
3520 for (img
= 0; img
< srcDepth
; img
++) {
3521 GLubyte
*dstRow
= dstSlices
[img
];
3523 for (row
= 0; row
< srcHeight
; row
++) {
3524 GLuint
*dstUI
= (GLuint
*) dstRow
;
3525 for (col
= 0; col
< srcWidth
; col
++) {
3528 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
3529 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
3530 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
3531 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
3532 dstUI
[col
] = PACK_COLOR_2101010_US(a
, b
, g
, r
);
3535 dstRow
+= dstRowStride
;
3538 free((void *) tempImage
);
3544 _mesa_texstore_null(TEXSTORE_PARAMS
)
3546 (void) ctx
; (void) dims
;
3547 (void) baseInternalFormat
;
3549 (void) dstRowStride
; (void) dstSlices
,
3550 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3551 (void) srcFormat
; (void) srcType
;
3555 /* should never happen */
3556 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3562 * Return the StoreTexImageFunc pointer to store an image in the given format.
3564 static StoreTexImageFunc
3565 _mesa_get_texstore_func(mesa_format format
)
3567 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3568 static GLboolean initialized
= GL_FALSE
;
3571 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
3573 table
[MESA_FORMAT_A8B8G8R8_UNORM
] = _mesa_texstore_rgba8888
;
3574 table
[MESA_FORMAT_R8G8B8A8_UNORM
] = _mesa_texstore_rgba8888
;
3575 table
[MESA_FORMAT_B8G8R8A8_UNORM
] = _mesa_texstore_argb8888
;
3576 table
[MESA_FORMAT_A8R8G8B8_UNORM
] = _mesa_texstore_argb8888
;
3577 table
[MESA_FORMAT_X8B8G8R8_UNORM
] = _mesa_texstore_rgba8888
;
3578 table
[MESA_FORMAT_R8G8B8X8_UNORM
] = _mesa_texstore_rgba8888
;
3579 table
[MESA_FORMAT_B8G8R8X8_UNORM
] = _mesa_texstore_argb8888
;
3580 table
[MESA_FORMAT_X8R8G8B8_UNORM
] = _mesa_texstore_argb8888
;
3581 table
[MESA_FORMAT_BGR_UNORM8
] = _mesa_texstore_rgb888
;
3582 table
[MESA_FORMAT_RGB_UNORM8
] = _mesa_texstore_bgr888
;
3583 table
[MESA_FORMAT_B5G6R5_UNORM
] = _mesa_texstore_rgb565
;
3584 table
[MESA_FORMAT_R5G6B5_UNORM
] = _mesa_texstore_rgb565
;
3585 table
[MESA_FORMAT_B4G4R4A4_UNORM
] = store_ubyte_texture
;
3586 table
[MESA_FORMAT_A4R4G4B4_UNORM
] = store_ubyte_texture
;
3587 table
[MESA_FORMAT_A1B5G5R5_UNORM
] = store_ubyte_texture
;
3588 table
[MESA_FORMAT_B5G5R5A1_UNORM
] = store_ubyte_texture
;
3589 table
[MESA_FORMAT_A1R5G5B5_UNORM
] = store_ubyte_texture
;
3590 table
[MESA_FORMAT_L4A4_UNORM
] = _mesa_texstore_unorm44
;
3591 table
[MESA_FORMAT_L8A8_UNORM
] = _mesa_texstore_unorm88
;
3592 table
[MESA_FORMAT_A8L8_UNORM
] = _mesa_texstore_unorm88
;
3593 table
[MESA_FORMAT_L16A16_UNORM
] = _mesa_texstore_unorm1616
;
3594 table
[MESA_FORMAT_A16L16_UNORM
] = _mesa_texstore_unorm1616
;
3595 table
[MESA_FORMAT_B2G3R3_UNORM
] = store_ubyte_texture
;
3596 table
[MESA_FORMAT_A_UNORM8
] = _mesa_texstore_unorm8
;
3597 table
[MESA_FORMAT_A_UNORM16
] = _mesa_texstore_unorm16
;
3598 table
[MESA_FORMAT_L_UNORM8
] = _mesa_texstore_unorm8
;
3599 table
[MESA_FORMAT_L_UNORM16
] = _mesa_texstore_unorm16
;
3600 table
[MESA_FORMAT_I_UNORM8
] = _mesa_texstore_unorm8
;
3601 table
[MESA_FORMAT_I_UNORM16
] = _mesa_texstore_unorm16
;
3602 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
3603 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
3604 table
[MESA_FORMAT_R_UNORM8
] = _mesa_texstore_unorm8
;
3605 table
[MESA_FORMAT_R8G8_UNORM
] = _mesa_texstore_unorm88
;
3606 table
[MESA_FORMAT_G8R8_UNORM
] = _mesa_texstore_unorm88
;
3607 table
[MESA_FORMAT_R_UNORM16
] = _mesa_texstore_unorm16
;
3608 table
[MESA_FORMAT_R16G16_UNORM
] = _mesa_texstore_unorm1616
;
3609 table
[MESA_FORMAT_G16R16_UNORM
] = _mesa_texstore_unorm1616
;
3610 table
[MESA_FORMAT_B10G10R10A2_UNORM
] = _mesa_texstore_argb2101010
;
3611 table
[MESA_FORMAT_S8_UINT_Z24_UNORM
] = _mesa_texstore_z24_s8
;
3612 table
[MESA_FORMAT_Z24_UNORM_S8_UINT
] = _mesa_texstore_s8_z24
;
3613 table
[MESA_FORMAT_Z_UNORM16
] = _mesa_texstore_z16
;
3614 table
[MESA_FORMAT_Z24_UNORM_X8_UINT
] = _mesa_texstore_x8_z24
;
3615 table
[MESA_FORMAT_X8_UINT_Z24_UNORM
] = _mesa_texstore_z24_x8
;
3616 table
[MESA_FORMAT_Z_UNORM32
] = _mesa_texstore_z32
;
3617 table
[MESA_FORMAT_S_UINT8
] = _mesa_texstore_s8
;
3618 table
[MESA_FORMAT_BGR_SRGB8
] = _mesa_texstore_srgb8
;
3619 table
[MESA_FORMAT_A8B8G8R8_SRGB
] = _mesa_texstore_srgba8
;
3620 table
[MESA_FORMAT_B8G8R8A8_SRGB
] = _mesa_texstore_sargb8
;
3621 table
[MESA_FORMAT_L_SRGB8
] = _mesa_texstore_sl8
;
3622 table
[MESA_FORMAT_L8A8_SRGB
] = _mesa_texstore_sla8
;
3623 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3624 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3625 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3626 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3627 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
3628 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
3629 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3630 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3631 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3632 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3633 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3634 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3635 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
3636 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
3637 table
[MESA_FORMAT_A_FLOAT32
] = _mesa_texstore_rgba_float32
;
3638 table
[MESA_FORMAT_A_FLOAT16
] = _mesa_texstore_rgba_float16
;
3639 table
[MESA_FORMAT_L_FLOAT32
] = _mesa_texstore_rgba_float32
;
3640 table
[MESA_FORMAT_L_FLOAT16
] = _mesa_texstore_rgba_float16
;
3641 table
[MESA_FORMAT_LA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3642 table
[MESA_FORMAT_LA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3643 table
[MESA_FORMAT_I_FLOAT32
] = _mesa_texstore_rgba_float32
;
3644 table
[MESA_FORMAT_I_FLOAT16
] = _mesa_texstore_rgba_float16
;
3645 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
3646 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
3647 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
3648 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
3649 table
[MESA_FORMAT_R_SNORM8
] = _mesa_texstore_snorm8
;
3650 table
[MESA_FORMAT_R8G8_SNORM
] = _mesa_texstore_snorm88
;
3651 table
[MESA_FORMAT_X8B8G8R8_SNORM
] = _mesa_texstore_signed_rgbx8888
;
3652 table
[MESA_FORMAT_A8B8G8R8_SNORM
] = _mesa_texstore_signed_rgba8888
;
3653 table
[MESA_FORMAT_R8G8B8A8_SNORM
] = _mesa_texstore_signed_rgba8888
;
3654 table
[MESA_FORMAT_R_SNORM16
] = _mesa_texstore_snorm16
;
3655 table
[MESA_FORMAT_R16G16_SNORM
] = _mesa_texstore_snorm1616
;
3656 table
[MESA_FORMAT_RGB_SNORM16
] = _mesa_texstore_signed_rgba_16
;
3657 table
[MESA_FORMAT_RGBA_SNORM16
] = _mesa_texstore_signed_rgba_16
;
3658 table
[MESA_FORMAT_RGBA_UNORM16
] = _mesa_texstore_rgba_16
;
3659 table
[MESA_FORMAT_R_RGTC1_UNORM
] = _mesa_texstore_red_rgtc1
;
3660 table
[MESA_FORMAT_R_RGTC1_SNORM
] = _mesa_texstore_signed_red_rgtc1
;
3661 table
[MESA_FORMAT_RG_RGTC2_UNORM
] = _mesa_texstore_rg_rgtc2
;
3662 table
[MESA_FORMAT_RG_RGTC2_SNORM
] = _mesa_texstore_signed_rg_rgtc2
;
3663 table
[MESA_FORMAT_L_LATC1_UNORM
] = _mesa_texstore_red_rgtc1
;
3664 table
[MESA_FORMAT_L_LATC1_SNORM
] = _mesa_texstore_signed_red_rgtc1
;
3665 table
[MESA_FORMAT_LA_LATC2_UNORM
] = _mesa_texstore_rg_rgtc2
;
3666 table
[MESA_FORMAT_LA_LATC2_SNORM
] = _mesa_texstore_signed_rg_rgtc2
;
3667 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
3668 table
[MESA_FORMAT_ETC2_RGB8
] = _mesa_texstore_etc2_rgb8
;
3669 table
[MESA_FORMAT_ETC2_SRGB8
] = _mesa_texstore_etc2_srgb8
;
3670 table
[MESA_FORMAT_ETC2_RGBA8_EAC
] = _mesa_texstore_etc2_rgba8_eac
;
3671 table
[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
] = _mesa_texstore_etc2_srgb8_alpha8_eac
;
3672 table
[MESA_FORMAT_ETC2_R11_EAC
] = _mesa_texstore_etc2_r11_eac
;
3673 table
[MESA_FORMAT_ETC2_RG11_EAC
] = _mesa_texstore_etc2_rg11_eac
;
3674 table
[MESA_FORMAT_ETC2_SIGNED_R11_EAC
] = _mesa_texstore_etc2_signed_r11_eac
;
3675 table
[MESA_FORMAT_ETC2_SIGNED_RG11_EAC
] = _mesa_texstore_etc2_signed_rg11_eac
;
3676 table
[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
] =
3677 _mesa_texstore_etc2_rgb8_punchthrough_alpha1
;
3678 table
[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
] =
3679 _mesa_texstore_etc2_srgb8_punchthrough_alpha1
;
3680 table
[MESA_FORMAT_A_SNORM8
] = _mesa_texstore_snorm8
;
3681 table
[MESA_FORMAT_L_SNORM8
] = _mesa_texstore_snorm8
;
3682 table
[MESA_FORMAT_L8A8_SNORM
] = _mesa_texstore_snorm88
;
3683 table
[MESA_FORMAT_I_SNORM8
] = _mesa_texstore_snorm8
;
3684 table
[MESA_FORMAT_A_SNORM16
] = _mesa_texstore_snorm16
;
3685 table
[MESA_FORMAT_L_SNORM16
] = _mesa_texstore_snorm16
;
3686 table
[MESA_FORMAT_LA_SNORM16
] = _mesa_texstore_snorm1616
;
3687 table
[MESA_FORMAT_I_SNORM16
] = _mesa_texstore_snorm16
;
3688 table
[MESA_FORMAT_R9G9B9E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
3689 table
[MESA_FORMAT_R11G11B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
3690 table
[MESA_FORMAT_Z_FLOAT32
] = _mesa_texstore_z32
;
3691 table
[MESA_FORMAT_Z32_FLOAT_S8X24_UINT
] = _mesa_texstore_z32f_x24s8
;
3693 table
[MESA_FORMAT_A_UINT8
] = _mesa_texstore_rgba_uint8
;
3694 table
[MESA_FORMAT_A_UINT16
] = _mesa_texstore_rgba_uint16
;
3695 table
[MESA_FORMAT_A_UINT32
] = _mesa_texstore_rgba_uint32
;
3696 table
[MESA_FORMAT_A_SINT8
] = _mesa_texstore_rgba_int8
;
3697 table
[MESA_FORMAT_A_SINT16
] = _mesa_texstore_rgba_int16
;
3698 table
[MESA_FORMAT_A_SINT32
] = _mesa_texstore_rgba_int32
;
3700 table
[MESA_FORMAT_I_UINT8
] = _mesa_texstore_rgba_uint8
;
3701 table
[MESA_FORMAT_I_UINT16
] = _mesa_texstore_rgba_uint16
;
3702 table
[MESA_FORMAT_I_UINT32
] = _mesa_texstore_rgba_uint32
;
3703 table
[MESA_FORMAT_I_SINT8
] = _mesa_texstore_rgba_int8
;
3704 table
[MESA_FORMAT_I_SINT16
] = _mesa_texstore_rgba_int16
;
3705 table
[MESA_FORMAT_I_SINT32
] = _mesa_texstore_rgba_int32
;
3707 table
[MESA_FORMAT_L_UINT8
] = _mesa_texstore_rgba_uint8
;
3708 table
[MESA_FORMAT_L_UINT16
] = _mesa_texstore_rgba_uint16
;
3709 table
[MESA_FORMAT_L_UINT32
] = _mesa_texstore_rgba_uint32
;
3710 table
[MESA_FORMAT_L_SINT8
] = _mesa_texstore_rgba_int8
;
3711 table
[MESA_FORMAT_L_SINT16
] = _mesa_texstore_rgba_int16
;
3712 table
[MESA_FORMAT_L_SINT32
] = _mesa_texstore_rgba_int32
;
3714 table
[MESA_FORMAT_LA_UINT8
] = _mesa_texstore_rgba_uint8
;
3715 table
[MESA_FORMAT_LA_UINT16
] = _mesa_texstore_rgba_uint16
;
3716 table
[MESA_FORMAT_LA_UINT32
] = _mesa_texstore_rgba_uint32
;
3717 table
[MESA_FORMAT_LA_SINT8
] = _mesa_texstore_rgba_int8
;
3718 table
[MESA_FORMAT_LA_SINT16
] = _mesa_texstore_rgba_int16
;
3719 table
[MESA_FORMAT_LA_SINT32
] = _mesa_texstore_rgba_int32
;
3721 table
[MESA_FORMAT_R_SINT8
] = _mesa_texstore_rgba_int8
;
3722 table
[MESA_FORMAT_RG_SINT8
] = _mesa_texstore_rgba_int8
;
3723 table
[MESA_FORMAT_RGB_SINT8
] = _mesa_texstore_rgba_int8
;
3724 table
[MESA_FORMAT_RGBA_SINT8
] = _mesa_texstore_rgba_int8
;
3725 table
[MESA_FORMAT_R_SINT16
] = _mesa_texstore_rgba_int16
;
3726 table
[MESA_FORMAT_RG_SINT16
] = _mesa_texstore_rgba_int16
;
3727 table
[MESA_FORMAT_RGB_SINT16
] = _mesa_texstore_rgba_int16
;
3728 table
[MESA_FORMAT_RGBA_SINT16
] = _mesa_texstore_rgba_int16
;
3729 table
[MESA_FORMAT_R_SINT32
] = _mesa_texstore_rgba_int32
;
3730 table
[MESA_FORMAT_RG_SINT32
] = _mesa_texstore_rgba_int32
;
3731 table
[MESA_FORMAT_RGB_SINT32
] = _mesa_texstore_rgba_int32
;
3732 table
[MESA_FORMAT_RGBA_SINT32
] = _mesa_texstore_rgba_int32
;
3734 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
3735 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
3736 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
3737 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
3738 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
3739 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
3740 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
3741 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
3742 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
3743 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
3744 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
3745 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
3747 table
[MESA_FORMAT_B10G10R10A2_UINT
] = _mesa_texstore_argb2101010_uint
;
3748 table
[MESA_FORMAT_R10G10B10A2_UINT
] = _mesa_texstore_abgr2101010_uint
;
3750 table
[MESA_FORMAT_B4G4R4X4_UNORM
] = store_ubyte_texture
;
3751 table
[MESA_FORMAT_B5G5R5X1_UNORM
] = store_ubyte_texture
;
3752 table
[MESA_FORMAT_R8G8B8X8_SNORM
] = _mesa_texstore_signed_rgbx8888
;
3753 table
[MESA_FORMAT_R8G8B8X8_SRGB
] = _mesa_texstore_srgba8
;
3754 table
[MESA_FORMAT_R8G8B8A8_SRGB
] = _mesa_texstore_srgba8
;
3755 table
[MESA_FORMAT_RGBX_UINT8
] = _mesa_texstore_rgba_uint8
;
3756 table
[MESA_FORMAT_RGBX_SINT8
] = _mesa_texstore_rgba_int8
;
3757 table
[MESA_FORMAT_B10G10R10X2_UNORM
] = _mesa_texstore_argb2101010
;
3758 table
[MESA_FORMAT_RGBX_UNORM16
] = _mesa_texstore_rgba_16
;
3759 table
[MESA_FORMAT_RGBX_SNORM16
] = _mesa_texstore_signed_rgba_16
;
3760 table
[MESA_FORMAT_RGBX_FLOAT16
] = _mesa_texstore_rgba_float16
;
3761 table
[MESA_FORMAT_RGBX_UINT16
] = _mesa_texstore_rgba_uint16
;
3762 table
[MESA_FORMAT_RGBX_SINT16
] = _mesa_texstore_rgba_int16
;
3763 table
[MESA_FORMAT_RGBX_FLOAT32
] = _mesa_texstore_rgba_float32
;
3764 table
[MESA_FORMAT_RGBX_UINT32
] = _mesa_texstore_rgba_uint32
;
3765 table
[MESA_FORMAT_RGBX_SINT32
] = _mesa_texstore_rgba_int32
;
3767 table
[MESA_FORMAT_R10G10B10A2_UNORM
] = _mesa_texstore_abgr2101010
;
3769 table
[MESA_FORMAT_G8R8_SNORM
] = _mesa_texstore_snorm88
;
3770 table
[MESA_FORMAT_G16R16_SNORM
] = _mesa_texstore_snorm1616
;
3772 table
[MESA_FORMAT_B8G8R8X8_SRGB
] = _mesa_texstore_sargb8
;
3774 initialized
= GL_TRUE
;
3777 ASSERT(table
[format
]);
3778 return table
[format
];
3783 _mesa_texstore_needs_transfer_ops(struct gl_context
*ctx
,
3784 GLenum baseInternalFormat
,
3785 mesa_format dstFormat
)
3789 /* There are different rules depending on the base format. */
3790 switch (baseInternalFormat
) {
3791 case GL_DEPTH_COMPONENT
:
3792 case GL_DEPTH_STENCIL
:
3793 return ctx
->Pixel
.DepthScale
!= 1.0f
||
3794 ctx
->Pixel
.DepthBias
!= 0.0f
;
3796 case GL_STENCIL_INDEX
:
3801 * Pixel transfer ops (scale, bias, table lookup) do not apply
3802 * to integer formats.
3804 dstType
= _mesa_get_format_datatype(dstFormat
);
3806 return dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
&&
3807 ctx
->_ImageTransferState
;
3813 _mesa_texstore_can_use_memcpy(struct gl_context
*ctx
,
3814 GLenum baseInternalFormat
, mesa_format dstFormat
,
3815 GLenum srcFormat
, GLenum srcType
,
3816 const struct gl_pixelstore_attrib
*srcPacking
)
3818 if (_mesa_texstore_needs_transfer_ops(ctx
, baseInternalFormat
, dstFormat
)) {
3822 /* The base internal format and the base Mesa format must match. */
3823 if (baseInternalFormat
!= _mesa_get_format_base_format(dstFormat
)) {
3827 /* The Mesa format must match the input format and type. */
3828 if (!_mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3829 srcPacking
->SwapBytes
)) {
3833 /* Depth texture data needs clamping in following cases:
3834 * - Floating point dstFormat with signed srcType: clamp to [0.0, 1.0].
3835 * - Fixed point dstFormat with signed srcType: clamp to [0, 2^n -1].
3837 * All the cases except one (float dstFormat with float srcType) are ruled
3838 * out by _mesa_format_matches_format_and_type() check above. Handle the
3839 * remaining case here.
3841 if ((baseInternalFormat
== GL_DEPTH_COMPONENT
||
3842 baseInternalFormat
== GL_DEPTH_STENCIL
) &&
3843 (srcType
== GL_FLOAT
||
3844 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)) {
3852 _mesa_texstore_memcpy(TEXSTORE_PARAMS
)
3854 if (!_mesa_texstore_can_use_memcpy(ctx
, baseInternalFormat
, dstFormat
,
3855 srcFormat
, srcType
, srcPacking
)) {
3859 memcpy_texture(ctx
, dims
,
3861 dstRowStride
, dstSlices
,
3862 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3863 srcAddr
, srcPacking
);
3869 * Store user data into texture memory.
3870 * Called via glTex[Sub]Image1/2/3D()
3871 * \return GL_TRUE for success, GL_FALSE for failure (out of memory).
3874 _mesa_texstore(TEXSTORE_PARAMS
)
3876 StoreTexImageFunc storeImage
;
3879 if (_mesa_texstore_memcpy(ctx
, dims
, baseInternalFormat
,
3881 dstRowStride
, dstSlices
,
3882 srcWidth
, srcHeight
, srcDepth
,
3883 srcFormat
, srcType
, srcAddr
, srcPacking
)) {
3887 storeImage
= _mesa_get_texstore_func(dstFormat
);
3889 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3891 dstRowStride
, dstSlices
,
3892 srcWidth
, srcHeight
, srcDepth
,
3893 srcFormat
, srcType
, srcAddr
, srcPacking
);
3899 * Normally, we'll only _write_ texel data to a texture when we map it.
3900 * But if the user is providing depth or stencil values and the texture
3901 * image is a combined depth/stencil format, we'll actually read from
3902 * the texture buffer too (in order to insert the depth or stencil values.
3903 * \param userFormat the user-provided image format
3904 * \param texFormat the destination texture format
3907 get_read_write_mode(GLenum userFormat
, mesa_format texFormat
)
3909 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
3910 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
3911 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
3913 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
3918 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
3920 * The source of the image data may be user memory or a PBO. In the later
3921 * case, we'll map the PBO, copy from it, then unmap it.
3924 store_texsubimage(struct gl_context
*ctx
,
3925 struct gl_texture_image
*texImage
,
3926 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3927 GLint width
, GLint height
, GLint depth
,
3928 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3929 const struct gl_pixelstore_attrib
*packing
,
3933 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
3934 const GLenum target
= texImage
->TexObject
->Target
;
3935 GLboolean success
= GL_FALSE
;
3936 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
3937 GLint srcImageStride
= 0;
3940 assert(xoffset
+ width
<= texImage
->Width
);
3941 assert(yoffset
+ height
<= texImage
->Height
);
3942 assert(zoffset
+ depth
<= texImage
->Depth
);
3948 case GL_TEXTURE_2D_ARRAY
:
3949 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3957 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3958 src
= (const GLubyte
*)
3959 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
3960 format
, type
, pixels
, packing
, caller
);
3964 /* compute slice info (and do some sanity checks) */
3967 case GL_TEXTURE_RECTANGLE
:
3968 case GL_TEXTURE_CUBE_MAP
:
3969 case GL_TEXTURE_EXTERNAL_OES
:
3970 /* one image slice, nothing special needs to be done */
3973 assert(height
== 1);
3975 assert(yoffset
== 0);
3976 assert(zoffset
== 0);
3978 case GL_TEXTURE_1D_ARRAY
:
3980 assert(zoffset
== 0);
3982 sliceOffset
= yoffset
;
3985 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
3987 case GL_TEXTURE_2D_ARRAY
:
3989 sliceOffset
= zoffset
;
3992 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
3996 /* we'll store 3D images as a series of slices */
3998 sliceOffset
= zoffset
;
3999 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4002 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4004 sliceOffset
= zoffset
;
4005 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4009 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4013 assert(numSlices
== 1 || srcImageStride
!= 0);
4015 for (slice
= 0; slice
< numSlices
; slice
++) {
4019 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4020 slice
+ sliceOffset
,
4021 xoffset
, yoffset
, width
, height
,
4022 mapMode
, &dstMap
, &dstRowStride
);
4024 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4025 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4026 * used for 3D images.
4028 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4029 texImage
->TexFormat
,
4032 width
, height
, 1, /* w, h, d */
4033 format
, type
, src
, packing
);
4035 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4038 src
+= srcImageStride
;
4045 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4047 _mesa_unmap_teximage_pbo(ctx
, packing
);
4053 * Fallback code for ctx->Driver.TexImage().
4054 * Basically, allocate storage for the texture image, then copy the
4055 * user's image into it.
4058 _mesa_store_teximage(struct gl_context
*ctx
,
4060 struct gl_texture_image
*texImage
,
4061 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4062 const struct gl_pixelstore_attrib
*packing
)
4064 assert(dims
== 1 || dims
== 2 || dims
== 3);
4066 if (texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
4069 /* allocate storage for texture data */
4070 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
4071 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
4075 store_texsubimage(ctx
, texImage
,
4076 0, 0, 0, texImage
->Width
, texImage
->Height
, texImage
->Depth
,
4077 format
, type
, pixels
, packing
, "glTexImage");
4082 * Fallback for Driver.TexSubImage().
4085 _mesa_store_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4086 struct gl_texture_image
*texImage
,
4087 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4088 GLint width
, GLint height
, GLint depth
,
4089 GLenum format
, GLenum type
, const void *pixels
,
4090 const struct gl_pixelstore_attrib
*packing
)
4092 store_texsubimage(ctx
, texImage
,
4093 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4094 format
, type
, pixels
, packing
, "glTexSubImage");
4099 * Fallback for Driver.CompressedTexImage()
4102 _mesa_store_compressed_teximage(struct gl_context
*ctx
, GLuint dims
,
4103 struct gl_texture_image
*texImage
,
4104 GLsizei imageSize
, const GLvoid
*data
)
4106 /* only 2D and 3D compressed images are supported at this time */
4108 _mesa_problem(ctx
, "Unexpected glCompressedTexImage1D call");
4112 /* This is pretty simple, because unlike the general texstore path we don't
4113 * have to worry about the usual image unpacking or image transfer
4117 ASSERT(texImage
->Width
> 0);
4118 ASSERT(texImage
->Height
> 0);
4119 ASSERT(texImage
->Depth
> 0);
4121 /* allocate storage for texture data */
4122 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
4123 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage%uD", dims
);
4127 _mesa_store_compressed_texsubimage(ctx
, dims
, texImage
,
4129 texImage
->Width
, texImage
->Height
, texImage
->Depth
,
4130 texImage
->TexFormat
,
4136 _mesa_compute_compressed_pixelstore(GLuint dims
, struct gl_texture_image
*texImage
,
4137 GLsizei width
, GLsizei height
, GLsizei depth
,
4138 const struct gl_pixelstore_attrib
*packing
,
4139 struct compressed_pixelstore
*store
)
4142 const mesa_format texFormat
= texImage
->TexFormat
;
4144 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4146 store
->SkipBytes
= 0;
4147 store
->TotalBytesPerRow
= store
->CopyBytesPerRow
=
4148 _mesa_format_row_stride(texFormat
, width
);
4149 store
->TotalRowsPerSlice
= store
->CopyRowsPerSlice
=
4150 (height
+ bh
- 1) / bh
;
4151 store
->CopySlices
= depth
;
4153 if (packing
->CompressedBlockWidth
&&
4154 packing
->CompressedBlockSize
) {
4156 bw
= packing
->CompressedBlockWidth
;
4158 if (packing
->RowLength
) {
4159 store
->TotalBytesPerRow
= packing
->CompressedBlockSize
*
4160 (packing
->RowLength
+ bw
- 1) / bw
;
4163 store
->SkipBytes
+= packing
->SkipPixels
* packing
->CompressedBlockSize
/ bw
;
4166 if (dims
> 1 && packing
->CompressedBlockHeight
&&
4167 packing
->CompressedBlockSize
) {
4169 bh
= packing
->CompressedBlockHeight
;
4171 store
->SkipBytes
+= packing
->SkipRows
* store
->TotalBytesPerRow
/ bh
;
4172 store
->CopyRowsPerSlice
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4174 if (packing
->ImageHeight
) {
4175 store
->TotalRowsPerSlice
= (packing
->ImageHeight
+ bh
- 1) / bh
;
4179 if (dims
> 2 && packing
->CompressedBlockDepth
&&
4180 packing
->CompressedBlockSize
) {
4182 int bd
= packing
->CompressedBlockDepth
;
4184 store
->SkipBytes
+= packing
->SkipImages
* store
->TotalBytesPerRow
*
4185 store
->TotalRowsPerSlice
/ bd
;
4191 * Fallback for Driver.CompressedTexSubImage()
4194 _mesa_store_compressed_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4195 struct gl_texture_image
*texImage
,
4196 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4197 GLsizei width
, GLsizei height
, GLsizei depth
,
4199 GLsizei imageSize
, const GLvoid
*data
)
4201 struct compressed_pixelstore store
;
4208 _mesa_problem(ctx
, "Unexpected 1D compressed texsubimage call");
4212 _mesa_compute_compressed_pixelstore(dims
, texImage
, width
, height
, depth
,
4213 &ctx
->Unpack
, &store
);
4215 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4216 data
= _mesa_validate_pbo_compressed_teximage(ctx
, dims
, imageSize
, data
,
4218 "glCompressedTexSubImage");
4222 src
= (const GLubyte
*) data
+ store
.SkipBytes
;
4224 for (slice
= 0; slice
< store
.CopySlices
; slice
++) {
4225 /* Map dest texture buffer */
4226 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
+ zoffset
,
4227 xoffset
, yoffset
, width
, height
,
4228 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4229 &dstMap
, &dstRowStride
);
4233 /* copy rows of blocks */
4234 for (i
= 0; i
< store
.CopyRowsPerSlice
; i
++) {
4235 memcpy(dstMap
, src
, store
.CopyBytesPerRow
);
4236 dstMap
+= dstRowStride
;
4237 src
+= store
.TotalBytesPerRow
;
4240 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ zoffset
);
4242 /* advance to next slice */
4243 src
+= store
.TotalBytesPerRow
* (store
.TotalRowsPerSlice
- store
.CopyRowsPerSlice
);
4246 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage%uD",
4251 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);