2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
33 * The GL texture image functions in teximage.c basically just do
34 * error checking and data structure allocation. They in turn call
35 * device driver functions which actually copy/convert/store the user's
38 * However, most device drivers will be able to use the fallback functions
39 * in this file. That is, most drivers will have the following bit of
41 * ctx->Driver.TexImage = _mesa_store_teximage;
42 * ctx->Driver.TexSubImage = _mesa_store_texsubimage;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
58 #include "format_pack.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
70 #include "texcompress_etc.h"
74 #include "glformats.h"
75 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
76 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
86 * Texture image storage function.
88 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
92 * Return GL_TRUE if the given image format is one that be converted
93 * to another format by swizzling.
96 can_swizzle(GLenum logicalBaseFormat
)
98 switch (logicalBaseFormat
) {
101 case GL_LUMINANCE_ALPHA
:
137 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
138 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
139 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
140 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
143 static const struct {
146 GLubyte from_rgba
[6];
147 } mappings
[MAX_IDX
] =
157 MAP4(ZERO
, ZERO
, ZERO
, 0),
187 MAP4(0, ZERO
, ZERO
, ONE
),
193 MAP4(ZERO
, 0, ZERO
, ONE
),
199 MAP4(ZERO
, ZERO
, 0, ONE
),
223 MAP4(0, 1, ZERO
, ONE
),
231 * Convert a GL image format enum to an IDX_* value (see above).
234 get_map_idx(GLenum value
)
237 case GL_LUMINANCE
: return IDX_LUMINANCE
;
238 case GL_ALPHA
: return IDX_ALPHA
;
239 case GL_INTENSITY
: return IDX_INTENSITY
;
240 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
241 case GL_RGB
: return IDX_RGB
;
242 case GL_RGBA
: return IDX_RGBA
;
243 case GL_RED
: return IDX_RED
;
244 case GL_GREEN
: return IDX_GREEN
;
245 case GL_BLUE
: return IDX_BLUE
;
246 case GL_BGR
: return IDX_BGR
;
247 case GL_BGRA
: return IDX_BGRA
;
248 case GL_ABGR_EXT
: return IDX_ABGR
;
249 case GL_RG
: return IDX_RG
;
251 _mesa_problem(NULL
, "Unexpected inFormat");
258 * When promoting texture formats (see below) we need to compute the
259 * mapping of dest components back to source components.
260 * This function does that.
261 * \param inFormat the incoming format of the texture
262 * \param outFormat the final texture format
263 * \return map[6] a full 6-component map
266 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
269 const int inFmt
= get_map_idx(inFormat
);
270 const int outFmt
= get_map_idx(outFormat
);
271 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
272 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
275 for (i
= 0; i
< 4; i
++)
276 map
[i
] = in2rgba
[rgba2out
[i
]];
282 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
283 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
284 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
296 * Make a temporary (color) texture image with GLfloat components.
297 * Apply all needed pixel unpacking and pixel transfer operations.
298 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
299 * Suppose the user specifies GL_LUMINANCE as the internal texture format
300 * but the graphics hardware doesn't support luminance textures. So, we might
301 * use an RGB hardware format instead.
302 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
304 * \param ctx the rendering context
305 * \param dims image dimensions: 1, 2 or 3
306 * \param logicalBaseFormat basic texture derived from the user's
307 * internal texture format value
308 * \param textureBaseFormat the actual basic format of the texture
309 * \param srcWidth source image width
310 * \param srcHeight source image height
311 * \param srcDepth source image depth
312 * \param srcFormat source image format
313 * \param srcType source image type
314 * \param srcAddr source image address
315 * \param srcPacking source image pixel packing
316 * \return resulting image with format = textureBaseFormat and type = GLfloat.
319 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
320 GLenum logicalBaseFormat
,
321 GLenum textureBaseFormat
,
322 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
323 GLenum srcFormat
, GLenum srcType
,
324 const GLvoid
*srcAddr
,
325 const struct gl_pixelstore_attrib
*srcPacking
,
326 GLbitfield transferOps
)
329 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
330 const GLint srcStride
=
331 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
335 ASSERT(dims
>= 1 && dims
<= 3);
337 ASSERT(logicalBaseFormat
== GL_RGBA
||
338 logicalBaseFormat
== GL_RGB
||
339 logicalBaseFormat
== GL_RG
||
340 logicalBaseFormat
== GL_RED
||
341 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
342 logicalBaseFormat
== GL_LUMINANCE
||
343 logicalBaseFormat
== GL_ALPHA
||
344 logicalBaseFormat
== GL_INTENSITY
||
345 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
347 ASSERT(textureBaseFormat
== GL_RGBA
||
348 textureBaseFormat
== GL_RGB
||
349 textureBaseFormat
== GL_RG
||
350 textureBaseFormat
== GL_RED
||
351 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
352 textureBaseFormat
== GL_LUMINANCE
||
353 textureBaseFormat
== GL_ALPHA
||
354 textureBaseFormat
== GL_INTENSITY
||
355 textureBaseFormat
== GL_DEPTH_COMPONENT
);
357 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
358 * components
* sizeof(GLfloat
));
363 for (img
= 0; img
< srcDepth
; img
++) {
365 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
369 for (row
= 0; row
< srcHeight
; row
++) {
370 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
371 dst
, srcFormat
, srcType
, src
,
372 srcPacking
, transferOps
);
373 dst
+= srcWidth
* components
;
378 if (logicalBaseFormat
!= textureBaseFormat
) {
380 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
381 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
386 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
387 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
388 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
390 /* The actual texture format should have at least as many components
391 * as the logical texture format.
393 ASSERT(texComponents
>= logComponents
);
395 newImage
= malloc(srcWidth
* srcHeight
* srcDepth
396 * texComponents
* sizeof(GLfloat
));
402 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
404 n
= srcWidth
* srcHeight
* srcDepth
;
405 for (i
= 0; i
< n
; i
++) {
407 for (k
= 0; k
< texComponents
; k
++) {
410 newImage
[i
* texComponents
+ k
] = 0.0F
;
412 newImage
[i
* texComponents
+ k
] = 1.0F
;
414 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
419 tempImage
= newImage
;
427 * Make temporary image with uint pixel values. Used for unsigned
428 * integer-valued textures.
431 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
432 GLenum logicalBaseFormat
,
433 GLenum textureBaseFormat
,
434 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
435 GLenum srcFormat
, GLenum srcType
,
436 const GLvoid
*srcAddr
,
437 const struct gl_pixelstore_attrib
*srcPacking
)
440 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
441 const GLint srcStride
=
442 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
446 ASSERT(dims
>= 1 && dims
<= 3);
448 ASSERT(logicalBaseFormat
== GL_RGBA
||
449 logicalBaseFormat
== GL_RGB
||
450 logicalBaseFormat
== GL_RG
||
451 logicalBaseFormat
== GL_RED
||
452 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
453 logicalBaseFormat
== GL_LUMINANCE
||
454 logicalBaseFormat
== GL_INTENSITY
||
455 logicalBaseFormat
== GL_ALPHA
);
457 ASSERT(textureBaseFormat
== GL_RGBA
||
458 textureBaseFormat
== GL_RGB
||
459 textureBaseFormat
== GL_RG
||
460 textureBaseFormat
== GL_RED
||
461 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
462 textureBaseFormat
== GL_LUMINANCE
||
463 textureBaseFormat
== GL_INTENSITY
||
464 textureBaseFormat
== GL_ALPHA
);
466 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
467 * components
* sizeof(GLuint
));
472 for (img
= 0; img
< srcDepth
; img
++) {
474 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
478 for (row
= 0; row
< srcHeight
; row
++) {
479 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
480 dst
, srcFormat
, srcType
, src
,
482 dst
+= srcWidth
* components
;
487 if (logicalBaseFormat
!= textureBaseFormat
) {
489 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
490 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
495 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
496 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
497 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
499 /* The actual texture format should have at least as many components
500 * as the logical texture format.
502 ASSERT(texComponents
>= logComponents
);
504 newImage
= malloc(srcWidth
* srcHeight
* srcDepth
505 * texComponents
* sizeof(GLuint
));
511 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
513 n
= srcWidth
* srcHeight
* srcDepth
;
514 for (i
= 0; i
< n
; i
++) {
516 for (k
= 0; k
< texComponents
; k
++) {
519 newImage
[i
* texComponents
+ k
] = 0;
521 newImage
[i
* texComponents
+ k
] = 1;
523 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
528 tempImage
= newImage
;
537 * Make a temporary (color) texture image with GLubyte components.
538 * Apply all needed pixel unpacking and pixel transfer operations.
539 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
540 * Suppose the user specifies GL_LUMINANCE as the internal texture format
541 * but the graphics hardware doesn't support luminance textures. So, we might
542 * use an RGB hardware format instead.
543 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
545 * \param ctx the rendering context
546 * \param dims image dimensions: 1, 2 or 3
547 * \param logicalBaseFormat basic texture derived from the user's
548 * internal texture format value
549 * \param textureBaseFormat the actual basic format of the texture
550 * \param srcWidth source image width
551 * \param srcHeight source image height
552 * \param srcDepth source image depth
553 * \param srcFormat source image format
554 * \param srcType source image type
555 * \param srcAddr source image address
556 * \param srcPacking source image pixel packing
557 * \return resulting image with format = textureBaseFormat and type = GLubyte.
560 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
561 GLenum logicalBaseFormat
,
562 GLenum textureBaseFormat
,
563 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
564 GLenum srcFormat
, GLenum srcType
,
565 const GLvoid
*srcAddr
,
566 const struct gl_pixelstore_attrib
*srcPacking
)
568 GLuint transferOps
= ctx
->_ImageTransferState
;
569 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
571 GLubyte
*tempImage
, *dst
;
573 ASSERT(dims
>= 1 && dims
<= 3);
575 ASSERT(logicalBaseFormat
== GL_RGBA
||
576 logicalBaseFormat
== GL_RGB
||
577 logicalBaseFormat
== GL_RG
||
578 logicalBaseFormat
== GL_RED
||
579 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
580 logicalBaseFormat
== GL_LUMINANCE
||
581 logicalBaseFormat
== GL_ALPHA
||
582 logicalBaseFormat
== GL_INTENSITY
);
584 ASSERT(textureBaseFormat
== GL_RGBA
||
585 textureBaseFormat
== GL_RGB
||
586 textureBaseFormat
== GL_RG
||
587 textureBaseFormat
== GL_RED
||
588 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
589 textureBaseFormat
== GL_LUMINANCE
||
590 textureBaseFormat
== GL_ALPHA
||
591 textureBaseFormat
== GL_INTENSITY
);
593 /* unpack and transfer the source image */
594 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
595 * components
* sizeof(GLubyte
));
601 for (img
= 0; img
< srcDepth
; img
++) {
602 const GLint srcStride
=
603 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
605 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
609 for (row
= 0; row
< srcHeight
; row
++) {
610 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
611 srcFormat
, srcType
, src
, srcPacking
,
613 dst
+= srcWidth
* components
;
618 if (logicalBaseFormat
!= textureBaseFormat
) {
619 /* one more conversion step */
620 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
621 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
626 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
627 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
628 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
630 /* The actual texture format should have at least as many components
631 * as the logical texture format.
633 ASSERT(texComponents
>= logComponents
);
635 newImage
= malloc(srcWidth
* srcHeight
* srcDepth
636 * texComponents
* sizeof(GLubyte
));
642 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
644 n
= srcWidth
* srcHeight
* srcDepth
;
645 for (i
= 0; i
< n
; i
++) {
647 for (k
= 0; k
< texComponents
; k
++) {
650 newImage
[i
* texComponents
+ k
] = 0;
652 newImage
[i
* texComponents
+ k
] = 255;
654 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
659 tempImage
= newImage
;
667 * Copy GLubyte pixels from <src> to <dst> with swizzling.
668 * \param dst destination pixels
669 * \param dstComponents number of color components in destination pixels
670 * \param src source pixels
671 * \param srcComponents number of color components in source pixels
672 * \param map the swizzle mapping. map[X] says where to find the X component
673 * in the source image's pixels. For example, if the source image
674 * is GL_BGRA and X = red, map[0] yields 2.
675 * \param count number of pixels to copy/swizzle.
678 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
679 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
681 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
684 for (i = 0; i < count; i++) { \
686 if (srcComps == 4) { \
687 COPY_4UBV(tmp, src); \
690 for (j = 0; j < srcComps; j++) { \
695 for (j = 0; j < dstComps; j++) { \
696 dst[j] = tmp[map[j]]; \
707 ASSERT(srcComponents
<= 4);
708 ASSERT(dstComponents
<= 4);
710 switch (dstComponents
) {
712 switch (srcComponents
) {
714 SWZ_CPY(dst
, src
, count
, 4, 4);
717 SWZ_CPY(dst
, src
, count
, 4, 3);
720 SWZ_CPY(dst
, src
, count
, 4, 2);
723 SWZ_CPY(dst
, src
, count
, 4, 1);
730 switch (srcComponents
) {
732 SWZ_CPY(dst
, src
, count
, 3, 4);
735 SWZ_CPY(dst
, src
, count
, 3, 3);
738 SWZ_CPY(dst
, src
, count
, 3, 2);
741 SWZ_CPY(dst
, src
, count
, 3, 1);
748 switch (srcComponents
) {
750 SWZ_CPY(dst
, src
, count
, 2, 4);
753 SWZ_CPY(dst
, src
, count
, 2, 3);
756 SWZ_CPY(dst
, src
, count
, 2, 2);
759 SWZ_CPY(dst
, src
, count
, 2, 1);
766 switch (srcComponents
) {
768 SWZ_CPY(dst
, src
, count
, 1, 4);
771 SWZ_CPY(dst
, src
, count
, 1, 3);
774 SWZ_CPY(dst
, src
, count
, 1, 2);
777 SWZ_CPY(dst
, src
, count
, 1, 1);
791 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
792 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
796 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
797 * mapping array depending on endianness.
799 static const GLubyte
*
800 type_mapping( GLenum srcType
)
804 case GL_UNSIGNED_BYTE
:
806 case GL_UNSIGNED_INT_8_8_8_8
:
807 return _mesa_little_endian() ? map_3210
: map_identity
;
808 case GL_UNSIGNED_INT_8_8_8_8_REV
:
809 return _mesa_little_endian() ? map_identity
: map_3210
;
817 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
818 * mapping array depending on pixelstore byte swapping state.
820 static const GLubyte
*
821 byteswap_mapping( GLboolean swapBytes
,
829 case GL_UNSIGNED_BYTE
:
831 case GL_UNSIGNED_INT_8_8_8_8
:
832 case GL_UNSIGNED_INT_8_8_8_8_REV
:
842 * Transfer a GLubyte texture image with component swizzling.
845 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
850 GLenum baseInternalFormat
,
852 const GLubyte
*rgba2dst
,
853 GLuint dstComponents
,
858 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
859 const GLvoid
*srcAddr
,
860 const struct gl_pixelstore_attrib
*srcPacking
)
862 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
863 const GLubyte
*srctype2ubyte
, *swap
;
864 GLubyte map
[4], src2base
[6], base2rgba
[6];
866 const GLint srcRowStride
=
867 _mesa_image_row_stride(srcPacking
, srcWidth
,
868 srcFormat
, GL_UNSIGNED_BYTE
);
869 const GLint srcImageStride
870 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
872 const GLubyte
*srcImage
873 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
874 srcWidth
, srcHeight
, srcFormat
,
875 GL_UNSIGNED_BYTE
, 0, 0, 0);
879 /* Translate from src->baseInternal->GL_RGBA->dst. This will
880 * correctly deal with RGBA->RGB->RGBA conversions where the final
881 * A value must be 0xff regardless of the incoming alpha values.
883 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
884 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
885 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
886 srctype2ubyte
= type_mapping(srcType
);
889 for (i
= 0; i
< 4; i
++)
890 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
892 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
894 if (srcComponents
== dstComponents
&&
895 srcRowStride
== dstRowStride
&&
896 srcRowStride
== srcWidth
* srcComponents
&&
898 /* 1 and 2D images only */
899 GLubyte
*dstImage
= dstSlices
[0];
900 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
901 srcWidth
* srcHeight
);
905 for (img
= 0; img
< srcDepth
; img
++) {
906 const GLubyte
*srcRow
= srcImage
;
907 GLubyte
*dstRow
= dstSlices
[img
];
908 for (row
= 0; row
< srcHeight
; row
++) {
909 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
910 dstRow
+= dstRowStride
;
911 srcRow
+= srcRowStride
;
913 srcImage
+= srcImageStride
;
920 * Teximage storage routine for when a simple memcpy will do.
921 * No pixel transfer operations or special texel encodings allowed.
922 * 1D, 2D and 3D images supported.
925 memcpy_texture(struct gl_context
*ctx
,
930 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
931 GLenum srcFormat
, GLenum srcType
,
932 const GLvoid
*srcAddr
,
933 const struct gl_pixelstore_attrib
*srcPacking
)
935 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
937 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
938 srcWidth
, srcHeight
, srcFormat
, srcType
);
939 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
940 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
941 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
942 const GLint bytesPerRow
= srcWidth
* texelBytes
;
944 if (dstRowStride
== srcRowStride
&&
945 dstRowStride
== bytesPerRow
) {
946 /* memcpy image by image */
948 for (img
= 0; img
< srcDepth
; img
++) {
949 GLubyte
*dstImage
= dstSlices
[img
];
950 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
951 srcImage
+= srcImageStride
;
955 /* memcpy row by row */
957 for (img
= 0; img
< srcDepth
; img
++) {
958 const GLubyte
*srcRow
= srcImage
;
959 GLubyte
*dstRow
= dstSlices
[img
];
960 for (row
= 0; row
< srcHeight
; row
++) {
961 memcpy(dstRow
, srcRow
, bytesPerRow
);
962 dstRow
+= dstRowStride
;
963 srcRow
+= srcRowStride
;
965 srcImage
+= srcImageStride
;
972 * General-case function for storing a color texture images with
973 * components that can be represented with ubytes. Example destination
974 * texture formats are MESA_FORMAT_ARGB888, ARGB4444, RGB565.
977 store_ubyte_texture(TEXSTORE_PARAMS
)
979 const GLint srcRowStride
= srcWidth
* 4 * sizeof(GLubyte
);
980 GLubyte
*tempImage
, *src
;
983 tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
986 srcWidth
, srcHeight
, srcDepth
,
987 srcFormat
, srcType
, srcAddr
,
993 for (img
= 0; img
< srcDepth
; img
++) {
994 _mesa_pack_ubyte_rgba_rect(dstFormat
, srcWidth
, srcHeight
,
996 dstSlices
[img
], dstRowStride
);
997 src
+= srcHeight
* srcRowStride
;
1008 * Store a 32-bit integer or float depth component texture image.
1011 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1013 const GLuint depthScale
= 0xffffffff;
1016 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
1017 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
1018 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
1020 if (dstFormat
== MESA_FORMAT_Z32
)
1021 dstType
= GL_UNSIGNED_INT
;
1028 for (img
= 0; img
< srcDepth
; img
++) {
1029 GLubyte
*dstRow
= dstSlices
[img
];
1030 for (row
= 0; row
< srcHeight
; row
++) {
1031 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1032 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1033 _mesa_unpack_depth_span(ctx
, srcWidth
,
1035 depthScale
, srcType
, src
, srcPacking
);
1036 dstRow
+= dstRowStride
;
1045 * Store a 24-bit integer depth component texture image.
1048 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1050 const GLuint depthScale
= 0xffffff;
1053 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1058 for (img
= 0; img
< srcDepth
; img
++) {
1059 GLubyte
*dstRow
= dstSlices
[img
];
1060 for (row
= 0; row
< srcHeight
; row
++) {
1061 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1062 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1063 _mesa_unpack_depth_span(ctx
, srcWidth
,
1064 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1065 depthScale
, srcType
, src
, srcPacking
);
1066 dstRow
+= dstRowStride
;
1075 * Store a 24-bit integer depth component texture image.
1078 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1080 const GLuint depthScale
= 0xffffff;
1083 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1088 for (img
= 0; img
< srcDepth
; img
++) {
1089 GLubyte
*dstRow
= dstSlices
[img
];
1090 for (row
= 0; row
< srcHeight
; row
++) {
1091 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1092 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1093 GLuint
*dst
= (GLuint
*) dstRow
;
1095 _mesa_unpack_depth_span(ctx
, srcWidth
,
1096 GL_UNSIGNED_INT
, dst
,
1097 depthScale
, srcType
, src
, srcPacking
);
1098 for (i
= 0; i
< srcWidth
; i
++)
1100 dstRow
+= dstRowStride
;
1109 * Store a 16-bit integer depth component texture image.
1112 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1114 const GLuint depthScale
= 0xffff;
1116 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1117 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1122 for (img
= 0; img
< srcDepth
; img
++) {
1123 GLubyte
*dstRow
= dstSlices
[img
];
1124 for (row
= 0; row
< srcHeight
; row
++) {
1125 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1126 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1127 GLushort
*dst16
= (GLushort
*) dstRow
;
1128 _mesa_unpack_depth_span(ctx
, srcWidth
,
1129 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1130 srcType
, src
, srcPacking
);
1131 dstRow
+= dstRowStride
;
1140 * Store an rgb565 or rgb565_rev texture image.
1143 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1145 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1146 dstFormat
== MESA_FORMAT_RGB565_REV
);
1147 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1149 if (!ctx
->_ImageTransferState
&&
1150 !srcPacking
->SwapBytes
&&
1151 baseInternalFormat
== GL_RGB
&&
1152 srcFormat
== GL_RGB
&&
1153 srcType
== GL_UNSIGNED_BYTE
&&
1155 /* do optimized tex store */
1156 const GLint srcRowStride
=
1157 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1158 const GLubyte
*src
= (const GLubyte
*)
1159 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1160 srcFormat
, srcType
, 0, 0, 0);
1161 GLubyte
*dst
= dstSlices
[0];
1163 for (row
= 0; row
< srcHeight
; row
++) {
1164 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1165 GLushort
*dstUS
= (GLushort
*) dst
;
1166 /* check for byteswapped format */
1167 if (dstFormat
== MESA_FORMAT_RGB565
) {
1168 for (col
= 0; col
< srcWidth
; col
++) {
1169 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1174 for (col
= 0; col
< srcWidth
; col
++) {
1175 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1179 dst
+= dstRowStride
;
1180 src
+= srcRowStride
;
1184 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1185 dstFormat
, dstRowStride
, dstSlices
,
1186 srcWidth
, srcHeight
, srcDepth
,
1187 srcFormat
, srcType
, srcAddr
, srcPacking
);
1194 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1197 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1199 const GLboolean littleEndian
= _mesa_little_endian();
1201 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1202 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1203 dstFormat
== MESA_FORMAT_RGBX8888
||
1204 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1205 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1207 if (!ctx
->_ImageTransferState
&&
1208 (srcType
== GL_UNSIGNED_BYTE
||
1209 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1210 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1211 can_swizzle(baseInternalFormat
) &&
1212 can_swizzle(srcFormat
)) {
1216 /* dstmap - how to swizzle from RGBA to dst format:
1218 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1219 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1220 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1221 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1234 _mesa_swizzle_ubyte_image(ctx
, dims
,
1239 dstRowStride
, dstSlices
,
1240 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1244 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1245 dstFormat
, dstRowStride
, dstSlices
,
1246 srcWidth
, srcHeight
, srcDepth
,
1247 srcFormat
, srcType
, srcAddr
, srcPacking
);
1254 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1256 const GLboolean littleEndian
= _mesa_little_endian();
1258 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1259 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1260 dstFormat
== MESA_FORMAT_XRGB8888
||
1261 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1262 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1264 if (!ctx
->_ImageTransferState
&&
1265 !srcPacking
->SwapBytes
&&
1266 (dstFormat
== MESA_FORMAT_ARGB8888
||
1267 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1268 srcFormat
== GL_RGB
&&
1269 (baseInternalFormat
== GL_RGBA
||
1270 baseInternalFormat
== GL_RGB
) &&
1271 srcType
== GL_UNSIGNED_BYTE
) {
1273 for (img
= 0; img
< srcDepth
; img
++) {
1274 const GLint srcRowStride
=
1275 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1276 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1277 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1278 GLubyte
*dstRow
= dstSlices
[img
];
1279 for (row
= 0; row
< srcHeight
; row
++) {
1280 GLuint
*d4
= (GLuint
*) dstRow
;
1281 for (col
= 0; col
< srcWidth
; col
++) {
1282 d4
[col
] = PACK_COLOR_8888(0xff,
1283 srcRow
[col
* 3 + RCOMP
],
1284 srcRow
[col
* 3 + GCOMP
],
1285 srcRow
[col
* 3 + BCOMP
]);
1287 dstRow
+= dstRowStride
;
1288 srcRow
+= srcRowStride
;
1292 else if (!ctx
->_ImageTransferState
&&
1293 !srcPacking
->SwapBytes
&&
1294 dstFormat
== MESA_FORMAT_ARGB8888
&&
1295 srcFormat
== GL_LUMINANCE_ALPHA
&&
1296 baseInternalFormat
== GL_RGBA
&&
1297 srcType
== GL_UNSIGNED_BYTE
) {
1298 /* special case of storing LA -> ARGB8888 */
1300 const GLint srcRowStride
=
1301 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1302 for (img
= 0; img
< srcDepth
; img
++) {
1303 const GLubyte
*srcRow
= (const GLubyte
*)
1304 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
,
1305 srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1306 GLubyte
*dstRow
= dstSlices
[img
];
1307 for (row
= 0; row
< srcHeight
; row
++) {
1308 GLuint
*d4
= (GLuint
*) dstRow
;
1309 for (col
= 0; col
< srcWidth
; col
++) {
1310 GLubyte l
= srcRow
[col
* 2 + 0], a
= srcRow
[col
* 2 + 1];
1311 d4
[col
] = PACK_COLOR_8888(a
, l
, l
, l
);
1313 dstRow
+= dstRowStride
;
1314 srcRow
+= srcRowStride
;
1318 else if (!ctx
->_ImageTransferState
&&
1319 !srcPacking
->SwapBytes
&&
1320 dstFormat
== MESA_FORMAT_ARGB8888
&&
1321 srcFormat
== GL_RGBA
&&
1322 baseInternalFormat
== GL_RGBA
&&
1323 srcType
== GL_UNSIGNED_BYTE
) {
1324 /* same as above case, but src data has alpha too */
1325 GLint img
, row
, col
;
1326 /* For some reason, streaming copies to write-combined regions
1327 * are extremely sensitive to the characteristics of how the
1328 * source data is retrieved. By reordering the source reads to
1329 * be in-order, the speed of this operation increases by half.
1330 * Strangely the same isn't required for the RGB path, above.
1332 for (img
= 0; img
< srcDepth
; img
++) {
1333 const GLint srcRowStride
=
1334 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1335 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1336 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1337 GLubyte
*dstRow
= dstSlices
[img
];
1338 for (row
= 0; row
< srcHeight
; row
++) {
1339 GLuint
*d4
= (GLuint
*) dstRow
;
1340 for (col
= 0; col
< srcWidth
; col
++) {
1341 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1342 srcRow
[col
* 4 + RCOMP
],
1343 srcRow
[col
* 4 + GCOMP
],
1344 srcRow
[col
* 4 + BCOMP
]);
1346 dstRow
+= dstRowStride
;
1347 srcRow
+= srcRowStride
;
1351 else if (!ctx
->_ImageTransferState
&&
1352 (srcType
== GL_UNSIGNED_BYTE
||
1353 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1354 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1355 can_swizzle(baseInternalFormat
) &&
1356 can_swizzle(srcFormat
)) {
1360 /* dstmap - how to swizzle from RGBA to dst format:
1362 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1363 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1364 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1365 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1366 dstmap
[3] = 3; /* alpha */
1367 dstmap
[2] = 0; /* red */
1368 dstmap
[1] = 1; /* green */
1369 dstmap
[0] = 2; /* blue */
1372 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1373 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1374 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1375 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1382 _mesa_swizzle_ubyte_image(ctx
, dims
,
1389 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1393 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1394 dstFormat
, dstRowStride
, dstSlices
,
1395 srcWidth
, srcHeight
, srcDepth
,
1396 srcFormat
, srcType
, srcAddr
, srcPacking
);
1403 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1405 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1406 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1408 if (!ctx
->_ImageTransferState
&&
1409 !srcPacking
->SwapBytes
&&
1410 srcFormat
== GL_RGBA
&&
1411 srcType
== GL_UNSIGNED_BYTE
) {
1412 /* extract RGB from RGBA */
1413 GLint img
, row
, col
;
1414 for (img
= 0; img
< srcDepth
; img
++) {
1415 const GLint srcRowStride
=
1416 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1417 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1418 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1419 GLubyte
*dstRow
= dstSlices
[img
];
1420 for (row
= 0; row
< srcHeight
; row
++) {
1421 for (col
= 0; col
< srcWidth
; col
++) {
1422 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1423 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1424 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1426 dstRow
+= dstRowStride
;
1427 srcRow
+= srcRowStride
;
1431 else if (!ctx
->_ImageTransferState
&&
1432 srcType
== GL_UNSIGNED_BYTE
&&
1433 can_swizzle(baseInternalFormat
) &&
1434 can_swizzle(srcFormat
)) {
1438 /* dstmap - how to swizzle from RGBA to dst format:
1443 dstmap
[3] = ONE
; /* ? */
1445 _mesa_swizzle_ubyte_image(ctx
, dims
,
1450 dstRowStride
, dstSlices
,
1451 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1455 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1456 dstFormat
, dstRowStride
, dstSlices
,
1457 srcWidth
, srcHeight
, srcDepth
,
1458 srcFormat
, srcType
, srcAddr
, srcPacking
);
1465 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1467 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1468 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1470 if (!ctx
->_ImageTransferState
&&
1471 !srcPacking
->SwapBytes
&&
1472 srcFormat
== GL_RGBA
&&
1473 srcType
== GL_UNSIGNED_BYTE
) {
1474 /* extract BGR from RGBA */
1476 for (img
= 0; img
< srcDepth
; img
++) {
1477 const GLint srcRowStride
=
1478 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1479 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1480 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1481 GLubyte
*dstRow
= dstSlices
[img
];
1482 for (row
= 0; row
< srcHeight
; row
++) {
1483 for (col
= 0; col
< srcWidth
; col
++) {
1484 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1485 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1486 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1488 dstRow
+= dstRowStride
;
1489 srcRow
+= srcRowStride
;
1493 else if (!ctx
->_ImageTransferState
&&
1494 srcType
== GL_UNSIGNED_BYTE
&&
1495 can_swizzle(baseInternalFormat
) &&
1496 can_swizzle(srcFormat
)) {
1500 /* dstmap - how to swizzle from RGBA to dst format:
1505 dstmap
[3] = ONE
; /* ? */
1507 _mesa_swizzle_ubyte_image(ctx
, dims
,
1512 dstRowStride
, dstSlices
,
1513 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1517 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1518 dstFormat
, dstRowStride
, dstSlices
,
1519 srcWidth
, srcHeight
, srcDepth
,
1520 srcFormat
, srcType
, srcAddr
, srcPacking
);
1527 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1529 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
||
1530 dstFormat
== MESA_FORMAT_XRGB2101010_UNORM
);
1531 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1535 /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0
1536 * if the internal format is RGB. */
1537 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1540 srcWidth
, srcHeight
, srcDepth
,
1541 srcFormat
, srcType
, srcAddr
,
1543 ctx
->_ImageTransferState
);
1544 const GLfloat
*src
= tempImage
;
1545 GLint img
, row
, col
;
1548 for (img
= 0; img
< srcDepth
; img
++) {
1549 GLubyte
*dstRow
= dstSlices
[img
];
1550 if (baseInternalFormat
== GL_RGBA
|| baseInternalFormat
== GL_RGB
) {
1551 for (row
= 0; row
< srcHeight
; row
++) {
1552 GLuint
*dstUI
= (GLuint
*) dstRow
;
1553 for (col
= 0; col
< srcWidth
; col
++) {
1556 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1557 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1558 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1559 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1560 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1563 dstRow
+= dstRowStride
;
1569 free((void *) tempImage
);
1576 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1579 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1581 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1583 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
1584 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1588 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1591 srcWidth
, srcHeight
, srcDepth
,
1592 srcFormat
, srcType
, srcAddr
,
1594 const GLubyte
*src
= tempImage
;
1595 GLint img
, row
, col
;
1598 for (img
= 0; img
< srcDepth
; img
++) {
1599 GLubyte
*dstRow
= dstSlices
[img
];
1600 for (row
= 0; row
< srcHeight
; row
++) {
1601 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1602 for (col
= 0; col
< srcWidth
; col
++) {
1603 /* src[0] is luminance, src[1] is alpha */
1604 dstUS
[col
] = PACK_COLOR_44( src
[1],
1608 dstRow
+= dstRowStride
;
1611 free((void *) tempImage
);
1618 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1621 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1623 const GLboolean littleEndian
= _mesa_little_endian();
1624 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1626 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1627 dstFormat
== MESA_FORMAT_AL88_REV
||
1628 dstFormat
== MESA_FORMAT_GR88
||
1629 dstFormat
== MESA_FORMAT_RG88
);
1630 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1632 if (!ctx
->_ImageTransferState
&&
1634 srcType
== GL_UNSIGNED_BYTE
&&
1635 can_swizzle(baseInternalFormat
) &&
1636 can_swizzle(srcFormat
)) {
1639 /* dstmap - how to swizzle from RGBA to dst format:
1641 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
1642 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
1643 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
1653 if ((littleEndian
&& dstFormat
== MESA_FORMAT_GR88
) ||
1654 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88
)) {
1663 dstmap
[2] = ZERO
; /* ? */
1664 dstmap
[3] = ONE
; /* ? */
1666 _mesa_swizzle_ubyte_image(ctx
, dims
,
1671 dstRowStride
, dstSlices
,
1672 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1677 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1680 srcWidth
, srcHeight
, srcDepth
,
1681 srcFormat
, srcType
, srcAddr
,
1683 const GLubyte
*src
= tempImage
;
1684 GLint img
, row
, col
;
1687 for (img
= 0; img
< srcDepth
; img
++) {
1688 GLubyte
*dstRow
= dstSlices
[img
];
1689 for (row
= 0; row
< srcHeight
; row
++) {
1690 GLushort
*dstUS
= (GLushort
*) dstRow
;
1691 if (dstFormat
== MESA_FORMAT_AL88
||
1692 dstFormat
== MESA_FORMAT_GR88
) {
1693 for (col
= 0; col
< srcWidth
; col
++) {
1694 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1695 dstUS
[col
] = PACK_COLOR_88( src
[1],
1701 for (col
= 0; col
< srcWidth
; col
++) {
1702 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1703 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
1708 dstRow
+= dstRowStride
;
1711 free((void *) tempImage
);
1718 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
1721 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
1723 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1725 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
1726 dstFormat
== MESA_FORMAT_AL1616_REV
||
1727 dstFormat
== MESA_FORMAT_GR1616
||
1728 dstFormat
== MESA_FORMAT_RG1616
);
1729 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1733 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1736 srcWidth
, srcHeight
, srcDepth
,
1737 srcFormat
, srcType
, srcAddr
,
1739 ctx
->_ImageTransferState
);
1740 const GLfloat
*src
= tempImage
;
1741 GLint img
, row
, col
;
1744 for (img
= 0; img
< srcDepth
; img
++) {
1745 GLubyte
*dstRow
= dstSlices
[img
];
1746 for (row
= 0; row
< srcHeight
; row
++) {
1747 GLuint
*dstUI
= (GLuint
*) dstRow
;
1748 if (dstFormat
== MESA_FORMAT_AL1616
||
1749 dstFormat
== MESA_FORMAT_GR1616
) {
1750 for (col
= 0; col
< srcWidth
; col
++) {
1753 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1754 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1755 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
1760 for (col
= 0; col
< srcWidth
; col
++) {
1763 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1764 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1765 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
1769 dstRow
+= dstRowStride
;
1772 free((void *) tempImage
);
1778 /* Texstore for R16, A16, L16, I16. */
1780 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
1782 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1784 ASSERT(dstFormat
== MESA_FORMAT_R16
||
1785 dstFormat
== MESA_FORMAT_A16
||
1786 dstFormat
== MESA_FORMAT_L16
||
1787 dstFormat
== MESA_FORMAT_I16
);
1788 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1792 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1795 srcWidth
, srcHeight
, srcDepth
,
1796 srcFormat
, srcType
, srcAddr
,
1798 ctx
->_ImageTransferState
);
1799 const GLfloat
*src
= tempImage
;
1800 GLint img
, row
, col
;
1803 for (img
= 0; img
< srcDepth
; img
++) {
1804 GLubyte
*dstRow
= dstSlices
[img
];
1805 for (row
= 0; row
< srcHeight
; row
++) {
1806 GLushort
*dstUS
= (GLushort
*) dstRow
;
1807 for (col
= 0; col
< srcWidth
; col
++) {
1810 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
1814 dstRow
+= dstRowStride
;
1817 free((void *) tempImage
);
1824 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
1826 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
||
1827 dstFormat
== MESA_FORMAT_XBGR16161616_UNORM
);
1828 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
1832 /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0
1833 * if the internal format is RGB. */
1834 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1837 srcWidth
, srcHeight
, srcDepth
,
1838 srcFormat
, srcType
, srcAddr
,
1840 ctx
->_ImageTransferState
);
1841 const GLfloat
*src
= tempImage
;
1842 GLint img
, row
, col
;
1847 for (img
= 0; img
< srcDepth
; img
++) {
1848 GLubyte
*dstRow
= dstSlices
[img
];
1849 for (row
= 0; row
< srcHeight
; row
++) {
1850 GLushort
*dstUS
= (GLushort
*) dstRow
;
1851 for (col
= 0; col
< srcWidth
; col
++) {
1852 GLushort r
, g
, b
, a
;
1854 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
1855 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
1856 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
1857 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
1864 dstRow
+= dstRowStride
;
1867 free((void *) tempImage
);
1874 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
1876 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1878 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
1879 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
||
1880 dstFormat
== MESA_FORMAT_XBGR16161616_SNORM
);
1884 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1887 srcWidth
, srcHeight
, srcDepth
,
1888 srcFormat
, srcType
, srcAddr
,
1890 ctx
->_ImageTransferState
);
1891 const GLfloat
*src
= tempImage
;
1892 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
1893 GLint img
, row
, col
;
1898 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
1899 * 3 or 4 components/pixel here.
1901 for (img
= 0; img
< srcDepth
; img
++) {
1902 GLubyte
*dstRow
= dstSlices
[img
];
1903 for (row
= 0; row
< srcHeight
; row
++) {
1904 GLshort
*dstRowS
= (GLshort
*) dstRow
;
1905 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
1906 for (col
= 0; col
< srcWidth
; col
++) {
1908 for (c
= 0; c
< comps
; c
++) {
1910 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
1911 dstRowS
[col
* comps
+ c
] = p
;
1914 dstRow
+= dstRowStride
;
1915 src
+= 4 * srcWidth
;
1917 else if (dstFormat
== MESA_FORMAT_XBGR16161616_SNORM
) {
1918 for (col
= 0; col
< srcWidth
; col
++) {
1921 for (c
= 0; c
< 3; c
++) {
1923 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
1924 dstRowS
[col
* comps
+ c
] = p
;
1926 dstRowS
[col
* comps
+ 3] = 32767;
1928 dstRow
+= dstRowStride
;
1929 src
+= 3 * srcWidth
;
1932 for (col
= 0; col
< srcWidth
; col
++) {
1934 for (c
= 0; c
< comps
; c
++) {
1936 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
1937 dstRowS
[col
* comps
+ c
] = p
;
1940 dstRow
+= dstRowStride
;
1941 src
+= 3 * srcWidth
;
1945 free((void *) tempImage
);
1952 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
1955 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
1957 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1959 ASSERT(dstFormat
== MESA_FORMAT_A8
||
1960 dstFormat
== MESA_FORMAT_L8
||
1961 dstFormat
== MESA_FORMAT_I8
||
1962 dstFormat
== MESA_FORMAT_R8
);
1963 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1965 if (!ctx
->_ImageTransferState
&&
1966 srcType
== GL_UNSIGNED_BYTE
&&
1967 can_swizzle(baseInternalFormat
) &&
1968 can_swizzle(srcFormat
)) {
1971 /* dstmap - how to swizzle from RGBA to dst format:
1973 if (dstFormat
== MESA_FORMAT_A8
) {
1979 dstmap
[1] = ZERO
; /* ? */
1980 dstmap
[2] = ZERO
; /* ? */
1981 dstmap
[3] = ONE
; /* ? */
1983 _mesa_swizzle_ubyte_image(ctx
, dims
,
1988 dstRowStride
, dstSlices
,
1989 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1994 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1997 srcWidth
, srcHeight
, srcDepth
,
1998 srcFormat
, srcType
, srcAddr
,
2000 const GLubyte
*src
= tempImage
;
2001 GLint img
, row
, col
;
2004 for (img
= 0; img
< srcDepth
; img
++) {
2005 GLubyte
*dstRow
= dstSlices
[img
];
2006 for (row
= 0; row
< srcHeight
; row
++) {
2007 for (col
= 0; col
< srcWidth
; col
++) {
2008 dstRow
[col
] = src
[col
];
2010 dstRow
+= dstRowStride
;
2014 free((void *) tempImage
);
2022 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2025 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2027 const GLboolean littleEndian
= _mesa_little_endian();
2029 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2031 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2032 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2033 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2034 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2035 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2036 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2037 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2038 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2040 /* always just memcpy since no pixel transfer ops apply */
2041 memcpy_texture(ctx
, dims
,
2043 dstRowStride
, dstSlices
,
2044 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2045 srcAddr
, srcPacking
);
2047 /* Check if we need byte swapping */
2048 /* XXX the logic here _might_ be wrong */
2049 if (srcPacking
->SwapBytes
^
2050 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2051 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2054 for (img
= 0; img
< srcDepth
; img
++) {
2055 GLubyte
*dstRow
= dstSlices
[img
];
2056 for (row
= 0; row
< srcHeight
; row
++) {
2057 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2058 dstRow
+= dstRowStride
;
2066 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2068 const GLboolean littleEndian
= _mesa_little_endian();
2069 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2071 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2072 ASSERT(texelBytes
== 2);
2073 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2074 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2075 (srcFormat
== GL_DUDV_ATI
));
2076 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2078 if (srcType
== GL_BYTE
) {
2081 /* dstmap - how to swizzle from RGBA to dst format:
2091 dstmap
[2] = ZERO
; /* ? */
2092 dstmap
[3] = ONE
; /* ? */
2094 _mesa_swizzle_ubyte_image(ctx
, dims
,
2095 GL_LUMINANCE_ALPHA
, /* hack */
2096 GL_UNSIGNED_BYTE
, /* hack */
2097 GL_LUMINANCE_ALPHA
, /* hack */
2099 dstRowStride
, dstSlices
,
2100 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2104 /* general path - note this is defined for 2d textures only */
2105 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2106 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2107 srcFormat
, srcType
);
2108 GLbyte
*tempImage
, *dst
, *src
;
2111 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
2112 * components
* sizeof(GLbyte
));
2116 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2117 srcWidth
, srcHeight
,
2122 for (row
= 0; row
< srcHeight
; row
++) {
2123 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2124 dst
, srcFormat
, srcType
, src
,
2126 dst
+= srcWidth
* components
;
2131 dst
= (GLbyte
*) dstSlices
[0];
2132 for (row
= 0; row
< srcHeight
; row
++) {
2133 memcpy(dst
, src
, srcWidth
* texelBytes
);
2134 dst
+= dstRowStride
;
2135 src
+= srcWidth
* texelBytes
;
2137 free((void *) tempImage
);
2144 * Store a texture in a signed normalized 8-bit format.
2147 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2149 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2151 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2152 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2153 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2154 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2155 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2159 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2162 srcWidth
, srcHeight
, srcDepth
,
2163 srcFormat
, srcType
, srcAddr
,
2165 ctx
->_ImageTransferState
);
2166 const GLfloat
*src
= tempImage
;
2167 GLint img
, row
, col
;
2170 for (img
= 0; img
< srcDepth
; img
++) {
2171 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2172 for (row
= 0; row
< srcHeight
; row
++) {
2173 for (col
= 0; col
< srcWidth
; col
++) {
2174 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2176 dstRow
+= dstRowStride
;
2180 free((void *) tempImage
);
2187 * Store a texture in a signed normalized two-channel 16-bit format.
2190 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2192 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2194 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2195 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2196 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2200 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2203 srcWidth
, srcHeight
, srcDepth
,
2204 srcFormat
, srcType
, srcAddr
,
2206 ctx
->_ImageTransferState
);
2207 const GLfloat
*src
= tempImage
;
2208 GLint img
, row
, col
;
2211 for (img
= 0; img
< srcDepth
; img
++) {
2212 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2213 for (row
= 0; row
< srcHeight
; row
++) {
2214 GLbyte
*dst
= dstRow
;
2215 for (col
= 0; col
< srcWidth
; col
++) {
2216 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2217 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2221 dstRow
+= dstRowStride
;
2224 free((void *) tempImage
);
2229 /* Texstore for signed R16, A16, L16, I16. */
2231 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2233 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2235 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2236 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2237 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2238 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2239 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2243 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2246 srcWidth
, srcHeight
, srcDepth
,
2247 srcFormat
, srcType
, srcAddr
,
2249 ctx
->_ImageTransferState
);
2250 const GLfloat
*src
= tempImage
;
2251 GLint img
, row
, col
;
2254 for (img
= 0; img
< srcDepth
; img
++) {
2255 GLubyte
*dstRow
= dstSlices
[img
];
2256 for (row
= 0; row
< srcHeight
; row
++) {
2257 GLshort
*dstUS
= (GLshort
*) dstRow
;
2258 for (col
= 0; col
< srcWidth
; col
++) {
2261 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2265 dstRow
+= dstRowStride
;
2268 free((void *) tempImage
);
2274 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2277 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2279 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2281 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2282 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2283 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2287 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2290 srcWidth
, srcHeight
, srcDepth
,
2291 srcFormat
, srcType
, srcAddr
,
2293 ctx
->_ImageTransferState
);
2294 const GLfloat
*src
= tempImage
;
2295 GLint img
, row
, col
;
2298 for (img
= 0; img
< srcDepth
; img
++) {
2299 GLubyte
*dstRow
= dstSlices
[img
];
2300 for (row
= 0; row
< srcHeight
; row
++) {
2301 GLshort
*dst
= (GLshort
*) dstRow
;
2302 for (col
= 0; col
< srcWidth
; col
++) {
2305 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2306 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2312 dstRow
+= dstRowStride
;
2315 free((void *) tempImage
);
2321 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888 or
2322 * MESA_FORMAT_XBGR8888_SNORM.
2325 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2327 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2329 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
||
2330 dstFormat
== MESA_FORMAT_XBGR8888_SNORM
);
2331 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2335 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2338 srcWidth
, srcHeight
, srcDepth
,
2339 srcFormat
, srcType
, srcAddr
,
2341 ctx
->_ImageTransferState
);
2342 const GLfloat
*srcRow
= tempImage
;
2343 GLint img
, row
, col
;
2346 for (img
= 0; img
< srcDepth
; img
++) {
2347 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2348 for (row
= 0; row
< srcHeight
; row
++) {
2349 GLbyte
*dst
= dstRow
;
2350 if (dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
) {
2351 for (col
= 0; col
< srcWidth
; col
++) {
2352 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2353 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2354 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2361 for (col
= 0; col
< srcWidth
; col
++) {
2362 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2363 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2364 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2370 dstRow
+= dstRowStride
;
2373 free((void *) tempImage
);
2381 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2382 * MESA_FORMAT_SIGNED_RGBA8888_REV
2385 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2387 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2389 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2390 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2391 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2395 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2398 srcWidth
, srcHeight
, srcDepth
,
2399 srcFormat
, srcType
, srcAddr
,
2401 ctx
->_ImageTransferState
);
2402 const GLfloat
*srcRow
= tempImage
;
2403 GLint img
, row
, col
;
2406 for (img
= 0; img
< srcDepth
; img
++) {
2407 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2408 for (row
= 0; row
< srcHeight
; row
++) {
2409 GLbyte
*dst
= dstRow
;
2410 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2411 for (col
= 0; col
< srcWidth
; col
++) {
2412 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2413 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2414 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2415 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2421 for (col
= 0; col
< srcWidth
; col
++) {
2422 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2423 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2424 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2425 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2430 dstRow
+= dstRowStride
;
2433 free((void *) tempImage
);
2440 * Store a combined depth/stencil texture image.
2443 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2445 const GLuint depthScale
= 0xffffff;
2446 const GLint srcRowStride
2447 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2450 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2451 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2452 srcFormat
== GL_DEPTH_COMPONENT
||
2453 srcFormat
== GL_STENCIL_INDEX
);
2454 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2456 if (srcFormat
== GL_DEPTH_COMPONENT
||
2457 srcFormat
== GL_STENCIL_INDEX
) {
2458 GLuint
*depth
= malloc(srcWidth
* sizeof(GLuint
));
2459 GLubyte
*stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2461 if (!depth
|| !stencil
) {
2467 /* In case we only upload depth we need to preserve the stencil */
2468 for (img
= 0; img
< srcDepth
; img
++) {
2469 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2471 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2472 srcWidth
, srcHeight
,
2475 for (row
= 0; row
< srcHeight
; row
++) {
2477 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2479 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2480 keepstencil
= GL_TRUE
;
2482 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2483 keepdepth
= GL_TRUE
;
2486 if (keepdepth
== GL_FALSE
)
2487 /* the 24 depth bits will be in the low position: */
2488 _mesa_unpack_depth_span(ctx
, srcWidth
,
2489 GL_UNSIGNED_INT
, /* dst type */
2490 keepstencil
? depth
: dstRow
, /* dst addr */
2492 srcType
, src
, srcPacking
);
2494 if (keepstencil
== GL_FALSE
)
2495 /* get the 8-bit stencil values */
2496 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2497 GL_UNSIGNED_BYTE
, /* dst type */
2498 stencil
, /* dst addr */
2499 srcType
, src
, srcPacking
,
2500 ctx
->_ImageTransferState
);
2502 for (i
= 0; i
< srcWidth
; i
++) {
2504 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2506 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2509 src
+= srcRowStride
;
2510 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2522 * Store a combined depth/stencil texture image.
2525 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2527 const GLuint depthScale
= 0xffffff;
2528 const GLint srcRowStride
2529 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2534 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2535 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2536 srcFormat
== GL_DEPTH_COMPONENT
||
2537 srcFormat
== GL_STENCIL_INDEX
);
2538 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2539 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2541 depth
= malloc(srcWidth
* sizeof(GLuint
));
2542 stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2544 if (!depth
|| !stencil
) {
2550 for (img
= 0; img
< srcDepth
; img
++) {
2551 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2553 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2554 srcWidth
, srcHeight
,
2557 for (row
= 0; row
< srcHeight
; row
++) {
2559 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2561 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2562 keepstencil
= GL_TRUE
;
2564 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2565 keepdepth
= GL_TRUE
;
2568 if (keepdepth
== GL_FALSE
)
2569 /* the 24 depth bits will be in the low position: */
2570 _mesa_unpack_depth_span(ctx
, srcWidth
,
2571 GL_UNSIGNED_INT
, /* dst type */
2572 keepstencil
? depth
: dstRow
, /* dst addr */
2574 srcType
, src
, srcPacking
);
2576 if (keepstencil
== GL_FALSE
)
2577 /* get the 8-bit stencil values */
2578 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2579 GL_UNSIGNED_BYTE
, /* dst type */
2580 stencil
, /* dst addr */
2581 srcType
, src
, srcPacking
,
2582 ctx
->_ImageTransferState
);
2584 /* merge stencil values into depth values */
2585 for (i
= 0; i
< srcWidth
; i
++) {
2587 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2589 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
2592 src
+= srcRowStride
;
2593 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2605 * Store simple 8-bit/value stencil texture data.
2608 _mesa_texstore_s8(TEXSTORE_PARAMS
)
2610 ASSERT(dstFormat
== MESA_FORMAT_S8
);
2611 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
2614 const GLint srcRowStride
2615 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2617 GLubyte
*stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2622 for (img
= 0; img
< srcDepth
; img
++) {
2623 GLubyte
*dstRow
= dstSlices
[img
];
2625 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2626 srcWidth
, srcHeight
,
2629 for (row
= 0; row
< srcHeight
; row
++) {
2632 /* get the 8-bit stencil values */
2633 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2634 GL_UNSIGNED_BYTE
, /* dst type */
2635 stencil
, /* dst addr */
2636 srcType
, src
, srcPacking
,
2637 ctx
->_ImageTransferState
);
2638 /* merge stencil values into depth values */
2639 for (i
= 0; i
< srcWidth
; i
++)
2640 dstRow
[i
] = stencil
[i
];
2642 src
+= srcRowStride
;
2643 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
2655 * Store an image in any of the formats:
2656 * _mesa_texformat_rgba_float32
2657 * _mesa_texformat_rgb_float32
2658 * _mesa_texformat_alpha_float32
2659 * _mesa_texformat_luminance_float32
2660 * _mesa_texformat_luminance_alpha_float32
2661 * _mesa_texformat_intensity_float32
2664 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2666 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2667 GLint components
= _mesa_components_in_format(baseFormat
);
2669 /* this forces alpha to 1 in _mesa_make_temp_float_image */
2670 if (dstFormat
== MESA_FORMAT_XBGR32323232_FLOAT
) {
2671 baseFormat
= GL_RGBA
;
2675 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2676 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2677 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
2678 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
2679 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
2680 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
2681 dstFormat
== MESA_FORMAT_R_FLOAT32
||
2682 dstFormat
== MESA_FORMAT_RG_FLOAT32
||
2683 dstFormat
== MESA_FORMAT_XBGR32323232_FLOAT
);
2684 ASSERT(baseInternalFormat
== GL_RGBA
||
2685 baseInternalFormat
== GL_RGB
||
2686 baseInternalFormat
== GL_ALPHA
||
2687 baseInternalFormat
== GL_LUMINANCE
||
2688 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2689 baseInternalFormat
== GL_INTENSITY
||
2690 baseInternalFormat
== GL_RED
||
2691 baseInternalFormat
== GL_RG
);
2692 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
2696 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2699 srcWidth
, srcHeight
, srcDepth
,
2700 srcFormat
, srcType
, srcAddr
,
2702 ctx
->_ImageTransferState
);
2703 const GLfloat
*srcRow
= tempImage
;
2708 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2709 for (img
= 0; img
< srcDepth
; img
++) {
2710 GLubyte
*dstRow
= dstSlices
[img
];
2711 for (row
= 0; row
< srcHeight
; row
++) {
2712 memcpy(dstRow
, srcRow
, bytesPerRow
);
2713 dstRow
+= dstRowStride
;
2714 srcRow
+= srcWidth
* components
;
2718 free((void *) tempImage
);
2726 * As above, but store 16-bit floats.
2729 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2731 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2732 GLint components
= _mesa_components_in_format(baseFormat
);
2734 /* this forces alpha to 1 in _mesa_make_temp_float_image */
2735 if (dstFormat
== MESA_FORMAT_XBGR16161616_FLOAT
) {
2736 baseFormat
= GL_RGBA
;
2740 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2741 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2742 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
2743 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
2744 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
2745 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
2746 dstFormat
== MESA_FORMAT_R_FLOAT16
||
2747 dstFormat
== MESA_FORMAT_RG_FLOAT16
||
2748 dstFormat
== MESA_FORMAT_XBGR16161616_FLOAT
);
2749 ASSERT(baseInternalFormat
== GL_RGBA
||
2750 baseInternalFormat
== GL_RGB
||
2751 baseInternalFormat
== GL_ALPHA
||
2752 baseInternalFormat
== GL_LUMINANCE
||
2753 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2754 baseInternalFormat
== GL_INTENSITY
||
2755 baseInternalFormat
== GL_RED
||
2756 baseInternalFormat
== GL_RG
);
2757 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
2761 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2764 srcWidth
, srcHeight
, srcDepth
,
2765 srcFormat
, srcType
, srcAddr
,
2767 ctx
->_ImageTransferState
);
2768 const GLfloat
*src
= tempImage
;
2772 for (img
= 0; img
< srcDepth
; img
++) {
2773 GLubyte
*dstRow
= dstSlices
[img
];
2774 for (row
= 0; row
< srcHeight
; row
++) {
2775 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2777 for (i
= 0; i
< srcWidth
* components
; i
++) {
2778 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2780 dstRow
+= dstRowStride
;
2781 src
+= srcWidth
* components
;
2785 free((void *) tempImage
);
2791 /* non-normalized, signed int8 */
2793 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
2795 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2796 GLint components
= _mesa_components_in_format(baseFormat
);
2798 /* this forces alpha to 1 in make_temp_uint_image */
2799 if (dstFormat
== MESA_FORMAT_XBGR8888_SINT
) {
2800 baseFormat
= GL_RGBA
;
2804 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
2805 dstFormat
== MESA_FORMAT_RG_INT8
||
2806 dstFormat
== MESA_FORMAT_RGB_INT8
||
2807 dstFormat
== MESA_FORMAT_RGBA_INT8
||
2808 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
2809 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
2810 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
2811 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
||
2812 dstFormat
== MESA_FORMAT_XBGR8888_SINT
);
2813 ASSERT(baseInternalFormat
== GL_RGBA
||
2814 baseInternalFormat
== GL_RGB
||
2815 baseInternalFormat
== GL_RG
||
2816 baseInternalFormat
== GL_RED
||
2817 baseInternalFormat
== GL_ALPHA
||
2818 baseInternalFormat
== GL_LUMINANCE
||
2819 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2820 baseInternalFormat
== GL_INTENSITY
);
2821 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
2825 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2828 srcWidth
, srcHeight
, srcDepth
,
2832 const GLuint
*src
= tempImage
;
2834 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2837 for (img
= 0; img
< srcDepth
; img
++) {
2838 GLubyte
*dstRow
= dstSlices
[img
];
2839 for (row
= 0; row
< srcHeight
; row
++) {
2840 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
2843 for (i
= 0; i
< srcWidth
* components
; i
++) {
2844 dstTexel
[i
] = (GLbyte
) MIN2(src
[i
], 0x7f);
2847 for (i
= 0; i
< srcWidth
* components
; i
++) {
2848 dstTexel
[i
] = (GLbyte
) CLAMP((GLint
) src
[i
], -0x80, 0x7f);
2851 dstRow
+= dstRowStride
;
2852 src
+= srcWidth
* components
;
2856 free((void *) tempImage
);
2862 /* non-normalized, signed int16 */
2864 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
2866 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2867 GLint components
= _mesa_components_in_format(baseFormat
);
2869 /* this forces alpha to 1 in make_temp_uint_image */
2870 if (dstFormat
== MESA_FORMAT_XBGR16161616_SINT
) {
2871 baseFormat
= GL_RGBA
;
2875 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
2876 dstFormat
== MESA_FORMAT_RG_INT16
||
2877 dstFormat
== MESA_FORMAT_RGB_INT16
||
2878 dstFormat
== MESA_FORMAT_RGBA_INT16
||
2879 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
2880 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
2881 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
2882 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
||
2883 dstFormat
== MESA_FORMAT_XBGR16161616_SINT
);
2884 ASSERT(baseInternalFormat
== GL_RGBA
||
2885 baseInternalFormat
== GL_RGB
||
2886 baseInternalFormat
== GL_RG
||
2887 baseInternalFormat
== GL_RED
||
2888 baseInternalFormat
== GL_ALPHA
||
2889 baseInternalFormat
== GL_LUMINANCE
||
2890 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2891 baseInternalFormat
== GL_INTENSITY
);
2892 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
2896 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2899 srcWidth
, srcHeight
, srcDepth
,
2903 const GLuint
*src
= tempImage
;
2905 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2908 for (img
= 0; img
< srcDepth
; img
++) {
2909 GLubyte
*dstRow
= dstSlices
[img
];
2910 for (row
= 0; row
< srcHeight
; row
++) {
2911 GLshort
*dstTexel
= (GLshort
*) dstRow
;
2914 for (i
= 0; i
< srcWidth
* components
; i
++) {
2915 dstTexel
[i
] = (GLshort
) MIN2(src
[i
], 0x7fff);
2918 for (i
= 0; i
< srcWidth
* components
; i
++) {
2919 dstTexel
[i
] = (GLshort
)CLAMP((GLint
) src
[i
], -0x8000, 0x7fff);
2922 dstRow
+= dstRowStride
;
2923 src
+= srcWidth
* components
;
2927 free((void *) tempImage
);
2933 /* non-normalized, signed int32 */
2935 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
2937 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2938 GLint components
= _mesa_components_in_format(baseFormat
);
2940 /* this forces alpha to 1 in make_temp_uint_image */
2941 if (dstFormat
== MESA_FORMAT_XBGR32323232_SINT
) {
2942 baseFormat
= GL_RGBA
;
2946 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
2947 dstFormat
== MESA_FORMAT_RG_INT32
||
2948 dstFormat
== MESA_FORMAT_RGB_INT32
||
2949 dstFormat
== MESA_FORMAT_RGBA_INT32
||
2950 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
2951 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
2952 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
2953 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
||
2954 dstFormat
== MESA_FORMAT_XBGR32323232_SINT
);
2955 ASSERT(baseInternalFormat
== GL_RGBA
||
2956 baseInternalFormat
== GL_RGB
||
2957 baseInternalFormat
== GL_RG
||
2958 baseInternalFormat
== GL_RED
||
2959 baseInternalFormat
== GL_ALPHA
||
2960 baseInternalFormat
== GL_LUMINANCE
||
2961 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2962 baseInternalFormat
== GL_INTENSITY
);
2963 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
2967 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2970 srcWidth
, srcHeight
, srcDepth
,
2974 const GLuint
*src
= tempImage
;
2976 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2979 for (img
= 0; img
< srcDepth
; img
++) {
2980 GLubyte
*dstRow
= dstSlices
[img
];
2981 for (row
= 0; row
< srcHeight
; row
++) {
2982 GLint
*dstTexel
= (GLint
*) dstRow
;
2985 for (i
= 0; i
< srcWidth
* components
; i
++) {
2986 dstTexel
[i
] = (GLint
) MIN2(src
[i
], 0x7fffffff);
2989 for (i
= 0; i
< srcWidth
* components
; i
++) {
2990 dstTexel
[i
] = (GLint
) src
[i
];
2993 dstRow
+= dstRowStride
;
2994 src
+= srcWidth
* components
;
2998 free((void *) tempImage
);
3004 /* non-normalized, unsigned int8 */
3006 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3008 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3009 GLint components
= _mesa_components_in_format(baseFormat
);
3011 /* this forces alpha to 1 in make_temp_uint_image */
3012 if (dstFormat
== MESA_FORMAT_XBGR8888_UINT
) {
3013 baseFormat
= GL_RGBA
;
3017 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3018 dstFormat
== MESA_FORMAT_RG_UINT8
||
3019 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3020 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3021 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3022 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3023 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3024 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
||
3025 dstFormat
== MESA_FORMAT_XBGR8888_UINT
);
3026 ASSERT(baseInternalFormat
== GL_RGBA
||
3027 baseInternalFormat
== GL_RGB
||
3028 baseInternalFormat
== GL_RG
||
3029 baseInternalFormat
== GL_RED
||
3030 baseInternalFormat
== GL_ALPHA
||
3031 baseInternalFormat
== GL_LUMINANCE
||
3032 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3033 baseInternalFormat
== GL_INTENSITY
);
3034 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3038 const GLuint
*tempImage
=
3039 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3040 srcWidth
, srcHeight
, srcDepth
,
3041 srcFormat
, srcType
, srcAddr
, srcPacking
);
3042 const GLuint
*src
= tempImage
;
3044 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3047 for (img
= 0; img
< srcDepth
; img
++) {
3048 GLubyte
*dstRow
= dstSlices
[img
];
3049 for (row
= 0; row
< srcHeight
; row
++) {
3050 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3053 for (i
= 0; i
< srcWidth
* components
; i
++) {
3054 dstTexel
[i
] = (GLubyte
) MIN2(src
[i
], 0xff);
3057 for (i
= 0; i
< srcWidth
* components
; i
++) {
3058 dstTexel
[i
] = (GLubyte
) CLAMP((GLint
) src
[i
], 0, 0xff);
3061 dstRow
+= dstRowStride
;
3062 src
+= srcWidth
* components
;
3066 free((void *) tempImage
);
3072 /* non-normalized, unsigned int16 */
3074 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3076 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3077 GLint components
= _mesa_components_in_format(baseFormat
);
3079 /* this forces alpha to 1 in make_temp_uint_image */
3080 if (dstFormat
== MESA_FORMAT_XBGR16161616_UINT
) {
3081 baseFormat
= GL_RGBA
;
3085 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3086 dstFormat
== MESA_FORMAT_RG_UINT16
||
3087 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3088 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3089 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3090 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3091 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3092 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
||
3093 dstFormat
== MESA_FORMAT_XBGR16161616_UINT
);
3094 ASSERT(baseInternalFormat
== GL_RGBA
||
3095 baseInternalFormat
== GL_RGB
||
3096 baseInternalFormat
== GL_RG
||
3097 baseInternalFormat
== GL_RED
||
3098 baseInternalFormat
== GL_ALPHA
||
3099 baseInternalFormat
== GL_LUMINANCE
||
3100 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3101 baseInternalFormat
== GL_INTENSITY
);
3102 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3106 const GLuint
*tempImage
=
3107 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3108 srcWidth
, srcHeight
, srcDepth
,
3109 srcFormat
, srcType
, srcAddr
, srcPacking
);
3110 const GLuint
*src
= tempImage
;
3112 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3115 for (img
= 0; img
< srcDepth
; img
++) {
3116 GLubyte
*dstRow
= dstSlices
[img
];
3117 for (row
= 0; row
< srcHeight
; row
++) {
3118 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3121 for (i
= 0; i
< srcWidth
* components
; i
++) {
3122 dstTexel
[i
] = (GLushort
) MIN2(src
[i
], 0xffff);
3125 for (i
= 0; i
< srcWidth
* components
; i
++) {
3126 dstTexel
[i
] = (GLushort
) CLAMP((GLint
) src
[i
], 0, 0xffff);
3129 dstRow
+= dstRowStride
;
3130 src
+= srcWidth
* components
;
3134 free((void *) tempImage
);
3140 /* non-normalized, unsigned int32 */
3142 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3144 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3145 GLint components
= _mesa_components_in_format(baseFormat
);
3147 /* this forces alpha to 1 in make_temp_uint_image */
3148 if (dstFormat
== MESA_FORMAT_XBGR32323232_UINT
) {
3149 baseFormat
= GL_RGBA
;
3153 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3154 dstFormat
== MESA_FORMAT_RG_UINT32
||
3155 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3156 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3157 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3158 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3159 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3160 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
||
3161 dstFormat
== MESA_FORMAT_XBGR32323232_UINT
);
3162 ASSERT(baseInternalFormat
== GL_RGBA
||
3163 baseInternalFormat
== GL_RGB
||
3164 baseInternalFormat
== GL_RG
||
3165 baseInternalFormat
== GL_RED
||
3166 baseInternalFormat
== GL_ALPHA
||
3167 baseInternalFormat
== GL_LUMINANCE
||
3168 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3169 baseInternalFormat
== GL_INTENSITY
);
3170 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3174 const GLuint
*tempImage
=
3175 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3176 srcWidth
, srcHeight
, srcDepth
,
3177 srcFormat
, srcType
, srcAddr
, srcPacking
);
3178 const GLuint
*src
= tempImage
;
3179 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3183 for (img
= 0; img
< srcDepth
; img
++) {
3184 GLubyte
*dstRow
= dstSlices
[img
];
3185 for (row
= 0; row
< srcHeight
; row
++) {
3186 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3189 for (i
= 0; i
< srcWidth
* components
; i
++) {
3190 dstTexel
[i
] = src
[i
];
3193 for (i
= 0; i
< srcWidth
* components
; i
++) {
3194 dstTexel
[i
] = MAX2((GLint
) src
[i
], 0);
3197 dstRow
+= dstRowStride
;
3198 src
+= srcWidth
* components
;
3202 free((void *) tempImage
);
3209 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3211 gl_format newDstFormat
;
3214 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3216 /* reuse normal rgb texstore code */
3217 newDstFormat
= MESA_FORMAT_RGB888
;
3219 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3221 dstRowStride
, dstSlices
,
3222 srcWidth
, srcHeight
, srcDepth
,
3224 srcAddr
, srcPacking
);
3230 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3232 gl_format newDstFormat
;
3235 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
||
3236 dstFormat
== MESA_FORMAT_XBGR8888_SRGB
);
3238 /* reuse normal rgba texstore code */
3239 if (dstFormat
== MESA_FORMAT_SRGBA8
) {
3240 newDstFormat
= MESA_FORMAT_RGBA8888
;
3242 else if (dstFormat
== MESA_FORMAT_XBGR8888_SRGB
) {
3243 newDstFormat
= MESA_FORMAT_RGBX8888_REV
;
3250 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3252 dstRowStride
, dstSlices
,
3253 srcWidth
, srcHeight
, srcDepth
,
3255 srcAddr
, srcPacking
);
3261 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3263 gl_format newDstFormat
;
3266 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3268 /* reuse normal rgba texstore code */
3269 newDstFormat
= MESA_FORMAT_ARGB8888
;
3271 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3273 dstRowStride
, dstSlices
,
3274 srcWidth
, srcHeight
, srcDepth
,
3276 srcAddr
, srcPacking
);
3282 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3284 gl_format newDstFormat
;
3287 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3289 newDstFormat
= MESA_FORMAT_L8
;
3291 /* _mesa_textore_a8 handles luminance8 too */
3292 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3294 dstRowStride
, dstSlices
,
3295 srcWidth
, srcHeight
, srcDepth
,
3297 srcAddr
, srcPacking
);
3303 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3305 gl_format newDstFormat
;
3308 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3310 /* reuse normal luminance/alpha texstore code */
3311 newDstFormat
= MESA_FORMAT_AL88
;
3313 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3315 dstRowStride
, dstSlices
,
3316 srcWidth
, srcHeight
, srcDepth
,
3318 srcAddr
, srcPacking
);
3323 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3325 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3327 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
3328 ASSERT(baseInternalFormat
== GL_RGB
);
3332 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3335 srcWidth
, srcHeight
, srcDepth
,
3336 srcFormat
, srcType
, srcAddr
,
3338 ctx
->_ImageTransferState
);
3339 const GLfloat
*srcRow
= tempImage
;
3340 GLint img
, row
, col
;
3343 for (img
= 0; img
< srcDepth
; img
++) {
3344 GLubyte
*dstRow
= dstSlices
[img
];
3345 for (row
= 0; row
< srcHeight
; row
++) {
3346 GLuint
*dstUI
= (GLuint
*)dstRow
;
3347 for (col
= 0; col
< srcWidth
; col
++) {
3348 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3350 dstRow
+= dstRowStride
;
3351 srcRow
+= srcWidth
* 3;
3355 free((void *) tempImage
);
3361 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
3363 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3365 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
3366 ASSERT(baseInternalFormat
== GL_RGB
);
3370 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3373 srcWidth
, srcHeight
, srcDepth
,
3374 srcFormat
, srcType
, srcAddr
,
3376 ctx
->_ImageTransferState
);
3377 const GLfloat
*srcRow
= tempImage
;
3378 GLint img
, row
, col
;
3381 for (img
= 0; img
< srcDepth
; img
++) {
3382 GLubyte
*dstRow
= dstSlices
[img
];
3383 for (row
= 0; row
< srcHeight
; row
++) {
3384 GLuint
*dstUI
= (GLuint
*)dstRow
;
3385 for (col
= 0; col
< srcWidth
; col
++) {
3386 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
3388 dstRow
+= dstRowStride
;
3389 srcRow
+= srcWidth
* 3;
3393 free((void *) tempImage
);
3400 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
3402 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
3403 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
3404 srcFormat
== GL_DEPTH_COMPONENT
||
3405 srcFormat
== GL_STENCIL_INDEX
);
3406 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
3407 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
3409 if (srcFormat
== GL_DEPTH_COMPONENT
||
3410 srcFormat
== GL_STENCIL_INDEX
) {
3412 const GLint srcRowStride
3413 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3416 /* In case we only upload depth we need to preserve the stencil */
3417 for (img
= 0; img
< srcDepth
; img
++) {
3418 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
3420 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3421 srcWidth
, srcHeight
,
3424 for (row
= 0; row
< srcHeight
; row
++) {
3425 /* The unpack functions with:
3426 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
3427 * only write their own dword, so the other dword (stencil
3428 * or depth) is preserved. */
3429 if (srcFormat
!= GL_STENCIL_INDEX
)
3430 _mesa_unpack_depth_span(ctx
, srcWidth
,
3431 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3432 dstRow
, /* dst addr */
3433 ~0U, srcType
, src
, srcPacking
);
3435 if (srcFormat
!= GL_DEPTH_COMPONENT
)
3436 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3437 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3438 dstRow
, /* dst addr */
3439 srcType
, src
, srcPacking
,
3440 ctx
->_ImageTransferState
);
3442 src
+= srcRowStride
;
3443 dstRow
+= dstRowStride
/ sizeof(uint64_t);
3451 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
3453 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3455 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
3456 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3460 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3463 srcWidth
, srcHeight
,
3464 srcDepth
, srcFormat
,
3467 const GLuint
*src
= tempImage
;
3468 GLint img
, row
, col
;
3469 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3472 for (img
= 0; img
< srcDepth
; img
++) {
3473 GLubyte
*dstRow
= dstSlices
[img
];
3475 for (row
= 0; row
< srcHeight
; row
++) {
3476 GLuint
*dstUI
= (GLuint
*) dstRow
;
3478 for (col
= 0; col
< srcWidth
; col
++) {
3480 r
= MIN2(src
[RCOMP
], 0x3ff);
3481 g
= MIN2(src
[GCOMP
], 0x3ff);
3482 b
= MIN2(src
[BCOMP
], 0x3ff);
3483 a
= MIN2(src
[ACOMP
], 0x003);
3484 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3488 for (col
= 0; col
< srcWidth
; col
++) {
3490 r
= CLAMP((GLint
) src
[RCOMP
], 0, 0x3ff);
3491 g
= CLAMP((GLint
) src
[GCOMP
], 0, 0x3ff);
3492 b
= CLAMP((GLint
) src
[BCOMP
], 0, 0x3ff);
3493 a
= CLAMP((GLint
) src
[ACOMP
], 0, 0x003);
3494 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3498 dstRow
+= dstRowStride
;
3501 free((void *) tempImage
);
3507 _mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS
)
3509 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3511 ASSERT(dstFormat
== MESA_FORMAT_ABGR2101010_UINT
);
3512 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3516 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3519 srcWidth
, srcHeight
,
3520 srcDepth
, srcFormat
,
3523 const GLuint
*src
= tempImage
;
3524 GLint img
, row
, col
;
3525 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3528 for (img
= 0; img
< srcDepth
; img
++) {
3529 GLubyte
*dstRow
= dstSlices
[img
];
3531 for (row
= 0; row
< srcHeight
; row
++) {
3532 GLuint
*dstUI
= (GLuint
*) dstRow
;
3534 for (col
= 0; col
< srcWidth
; col
++) {
3536 r
= MIN2(src
[RCOMP
], 0x3ff);
3537 g
= MIN2(src
[GCOMP
], 0x3ff);
3538 b
= MIN2(src
[BCOMP
], 0x3ff);
3539 a
= MIN2(src
[ACOMP
], 0x003);
3540 dstUI
[col
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | (r
);
3544 for (col
= 0; col
< srcWidth
; col
++) {
3546 r
= CLAMP((GLint
) src
[RCOMP
], 0, 0x3ff);
3547 g
= CLAMP((GLint
) src
[GCOMP
], 0, 0x3ff);
3548 b
= CLAMP((GLint
) src
[BCOMP
], 0, 0x3ff);
3549 a
= CLAMP((GLint
) src
[ACOMP
], 0, 0x003);
3550 dstUI
[col
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | (r
);
3554 dstRow
+= dstRowStride
;
3557 free((void *) tempImage
);
3563 _mesa_texstore_null(TEXSTORE_PARAMS
)
3565 (void) ctx
; (void) dims
;
3566 (void) baseInternalFormat
;
3568 (void) dstRowStride
; (void) dstSlices
,
3569 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3570 (void) srcFormat
; (void) srcType
;
3574 /* should never happen */
3575 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3581 * Return the StoreTexImageFunc pointer to store an image in the given format.
3583 static StoreTexImageFunc
3584 _mesa_get_texstore_func(gl_format format
)
3586 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3587 static GLboolean initialized
= GL_FALSE
;
3590 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
3592 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
3593 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
3594 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
3595 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
3596 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
3597 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
3598 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
3599 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
3600 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
3601 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
3602 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
3603 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
3604 table
[MESA_FORMAT_ARGB4444
] = store_ubyte_texture
;
3605 table
[MESA_FORMAT_ARGB4444_REV
] = store_ubyte_texture
;
3606 table
[MESA_FORMAT_RGBA5551
] = store_ubyte_texture
;
3607 table
[MESA_FORMAT_ARGB1555
] = store_ubyte_texture
;
3608 table
[MESA_FORMAT_ARGB1555_REV
] = store_ubyte_texture
;
3609 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
3610 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
3611 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
3612 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
3613 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
3614 table
[MESA_FORMAT_RGB332
] = store_ubyte_texture
;
3615 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
3616 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
3617 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
3618 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
3619 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
3620 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
3621 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
3622 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
3623 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
3624 table
[MESA_FORMAT_GR88
] = _mesa_texstore_unorm88
;
3625 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
3626 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
3627 table
[MESA_FORMAT_GR1616
] = _mesa_texstore_unorm1616
;
3628 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
3629 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
3630 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
3631 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
3632 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
3633 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
3634 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
3635 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
3636 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
3637 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
3638 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
3639 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
3640 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
3641 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
3642 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3643 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3644 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3645 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3646 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
3647 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
3648 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3649 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3650 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3651 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3652 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3653 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3654 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
3655 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
3656 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3657 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3658 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
3659 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
3660 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3661 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3662 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
3663 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
3664 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
3665 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
3666 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
3667 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
3668 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
3669 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
3670 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
3671 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
3672 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
3673 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
3674 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
3675 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
3676 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
3677 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
3678 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
3679 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
3680 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
3681 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
3682 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
3683 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
3684 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
3685 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
3686 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
3687 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
3688 table
[MESA_FORMAT_ETC2_RGB8
] = _mesa_texstore_etc2_rgb8
;
3689 table
[MESA_FORMAT_ETC2_SRGB8
] = _mesa_texstore_etc2_srgb8
;
3690 table
[MESA_FORMAT_ETC2_RGBA8_EAC
] = _mesa_texstore_etc2_rgba8_eac
;
3691 table
[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
] = _mesa_texstore_etc2_srgb8_alpha8_eac
;
3692 table
[MESA_FORMAT_ETC2_R11_EAC
] = _mesa_texstore_etc2_r11_eac
;
3693 table
[MESA_FORMAT_ETC2_RG11_EAC
] = _mesa_texstore_etc2_rg11_eac
;
3694 table
[MESA_FORMAT_ETC2_SIGNED_R11_EAC
] = _mesa_texstore_etc2_signed_r11_eac
;
3695 table
[MESA_FORMAT_ETC2_SIGNED_RG11_EAC
] = _mesa_texstore_etc2_signed_rg11_eac
;
3696 table
[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
] =
3697 _mesa_texstore_etc2_rgb8_punchthrough_alpha1
;
3698 table
[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
] =
3699 _mesa_texstore_etc2_srgb8_punchthrough_alpha1
;
3700 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
3701 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
3702 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
3703 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
3704 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
3705 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
3706 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
3707 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
3708 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
3709 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
3710 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
3711 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
3713 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
3714 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
3715 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
3716 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
3717 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
3718 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
3720 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
3721 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
3722 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
3723 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
3724 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
3725 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
3727 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
3728 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
3729 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
3730 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
3731 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
3732 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
3734 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
3735 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
3736 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
3737 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
3738 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
3739 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
3741 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
3742 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
3743 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
3744 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
3745 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
3746 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
3747 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
3748 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
3749 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
3750 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
3751 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
3752 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
3754 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
3755 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
3756 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
3757 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
3758 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
3759 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
3760 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
3761 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
3762 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
3763 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
3764 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
3765 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
3767 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
3768 table
[MESA_FORMAT_ABGR2101010_UINT
] = _mesa_texstore_abgr2101010_uint
;
3770 table
[MESA_FORMAT_XRGB4444_UNORM
] = store_ubyte_texture
;
3771 table
[MESA_FORMAT_XRGB1555_UNORM
] = store_ubyte_texture
;
3772 table
[MESA_FORMAT_XBGR8888_SNORM
] = _mesa_texstore_signed_rgbx8888
;
3773 table
[MESA_FORMAT_XBGR8888_SRGB
] = _mesa_texstore_srgba8
;
3774 table
[MESA_FORMAT_XBGR8888_UINT
] = _mesa_texstore_rgba_uint8
;
3775 table
[MESA_FORMAT_XBGR8888_SINT
] = _mesa_texstore_rgba_int8
;
3776 table
[MESA_FORMAT_XRGB2101010_UNORM
] = _mesa_texstore_argb2101010
;
3777 table
[MESA_FORMAT_XBGR16161616_UNORM
] = _mesa_texstore_rgba_16
;
3778 table
[MESA_FORMAT_XBGR16161616_SNORM
] = _mesa_texstore_signed_rgba_16
;
3779 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = _mesa_texstore_rgba_float16
;
3780 table
[MESA_FORMAT_XBGR16161616_UINT
] = _mesa_texstore_rgba_uint16
;
3781 table
[MESA_FORMAT_XBGR16161616_SINT
] = _mesa_texstore_rgba_int16
;
3782 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = _mesa_texstore_rgba_float32
;
3783 table
[MESA_FORMAT_XBGR32323232_UINT
] = _mesa_texstore_rgba_uint32
;
3784 table
[MESA_FORMAT_XBGR32323232_SINT
] = _mesa_texstore_rgba_int32
;
3786 initialized
= GL_TRUE
;
3789 ASSERT(table
[format
]);
3790 return table
[format
];
3795 _mesa_texstore_needs_transfer_ops(struct gl_context
*ctx
,
3796 GLenum baseInternalFormat
,
3797 gl_format dstFormat
)
3801 /* There are different rules depending on the base format. */
3802 switch (baseInternalFormat
) {
3803 case GL_DEPTH_COMPONENT
:
3804 case GL_DEPTH_STENCIL
:
3805 return ctx
->Pixel
.DepthScale
!= 1.0f
||
3806 ctx
->Pixel
.DepthBias
!= 0.0f
;
3808 case GL_STENCIL_INDEX
:
3813 * Pixel transfer ops (scale, bias, table lookup) do not apply
3814 * to integer formats.
3816 dstType
= _mesa_get_format_datatype(dstFormat
);
3818 return dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
&&
3819 ctx
->_ImageTransferState
;
3825 _mesa_texstore_can_use_memcpy(struct gl_context
*ctx
,
3826 GLenum baseInternalFormat
, gl_format dstFormat
,
3827 GLenum srcFormat
, GLenum srcType
,
3828 const struct gl_pixelstore_attrib
*srcPacking
)
3830 if (_mesa_texstore_needs_transfer_ops(ctx
, baseInternalFormat
, dstFormat
)) {
3834 /* The base internal format and the base Mesa format must match. */
3835 if (baseInternalFormat
!= _mesa_get_format_base_format(dstFormat
)) {
3839 /* The Mesa format must match the input format and type. */
3840 if (!_mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3841 srcPacking
->SwapBytes
)) {
3849 _mesa_texstore_memcpy(TEXSTORE_PARAMS
)
3851 if (!_mesa_texstore_can_use_memcpy(ctx
, baseInternalFormat
, dstFormat
,
3852 srcFormat
, srcType
, srcPacking
)) {
3856 memcpy_texture(ctx
, dims
,
3858 dstRowStride
, dstSlices
,
3859 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3860 srcAddr
, srcPacking
);
3866 * Store user data into texture memory.
3867 * Called via glTex[Sub]Image1/2/3D()
3870 _mesa_texstore(TEXSTORE_PARAMS
)
3872 StoreTexImageFunc storeImage
;
3875 if (_mesa_texstore_memcpy(ctx
, dims
, baseInternalFormat
,
3877 dstRowStride
, dstSlices
,
3878 srcWidth
, srcHeight
, srcDepth
,
3879 srcFormat
, srcType
, srcAddr
, srcPacking
)) {
3883 storeImage
= _mesa_get_texstore_func(dstFormat
);
3885 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3887 dstRowStride
, dstSlices
,
3888 srcWidth
, srcHeight
, srcDepth
,
3889 srcFormat
, srcType
, srcAddr
, srcPacking
);
3895 * Normally, we'll only _write_ texel data to a texture when we map it.
3896 * But if the user is providing depth or stencil values and the texture
3897 * image is a combined depth/stencil format, we'll actually read from
3898 * the texture buffer too (in order to insert the depth or stencil values.
3899 * \param userFormat the user-provided image format
3900 * \param texFormat the destination texture format
3903 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
3905 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
3906 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
3907 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
3909 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
3914 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
3916 * The source of the image data may be user memory or a PBO. In the later
3917 * case, we'll map the PBO, copy from it, then unmap it.
3920 store_texsubimage(struct gl_context
*ctx
,
3921 struct gl_texture_image
*texImage
,
3922 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3923 GLint width
, GLint height
, GLint depth
,
3924 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3925 const struct gl_pixelstore_attrib
*packing
,
3929 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
3930 const GLenum target
= texImage
->TexObject
->Target
;
3931 GLboolean success
= GL_FALSE
;
3932 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
3933 GLint srcImageStride
= 0;
3936 assert(xoffset
+ width
<= texImage
->Width
);
3937 assert(yoffset
+ height
<= texImage
->Height
);
3938 assert(zoffset
+ depth
<= texImage
->Depth
);
3944 case GL_TEXTURE_2D_ARRAY
:
3945 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3953 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3954 src
= (const GLubyte
*)
3955 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
3956 format
, type
, pixels
, packing
, caller
);
3960 /* compute slice info (and do some sanity checks) */
3963 case GL_TEXTURE_RECTANGLE
:
3964 case GL_TEXTURE_CUBE_MAP
:
3965 /* one image slice, nothing special needs to be done */
3968 assert(height
== 1);
3970 assert(yoffset
== 0);
3971 assert(zoffset
== 0);
3973 case GL_TEXTURE_1D_ARRAY
:
3975 assert(zoffset
== 0);
3977 sliceOffset
= yoffset
;
3980 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
3982 case GL_TEXTURE_2D_ARRAY
:
3984 sliceOffset
= zoffset
;
3987 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
3991 /* we'll store 3D images as a series of slices */
3993 sliceOffset
= zoffset
;
3994 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
3997 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3999 sliceOffset
= zoffset
;
4000 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4004 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4008 assert(numSlices
== 1 || srcImageStride
!= 0);
4010 for (slice
= 0; slice
< numSlices
; slice
++) {
4014 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4015 slice
+ sliceOffset
,
4016 xoffset
, yoffset
, width
, height
,
4017 mapMode
, &dstMap
, &dstRowStride
);
4019 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4020 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4021 * used for 3D images.
4023 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4024 texImage
->TexFormat
,
4027 width
, height
, 1, /* w, h, d */
4028 format
, type
, src
, packing
);
4030 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4033 src
+= srcImageStride
;
4040 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4042 _mesa_unmap_teximage_pbo(ctx
, packing
);
4048 * Fallback code for ctx->Driver.TexImage().
4049 * Basically, allocate storage for the texture image, then copy the
4050 * user's image into it.
4053 _mesa_store_teximage(struct gl_context
*ctx
,
4055 struct gl_texture_image
*texImage
,
4056 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4057 const struct gl_pixelstore_attrib
*packing
)
4059 assert(dims
== 1 || dims
== 2 || dims
== 3);
4061 if (texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
4064 /* allocate storage for texture data */
4065 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
4066 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
4070 store_texsubimage(ctx
, texImage
,
4071 0, 0, 0, texImage
->Width
, texImage
->Height
, texImage
->Depth
,
4072 format
, type
, pixels
, packing
, "glTexImage");
4077 * Fallback for Driver.TexSubImage().
4080 _mesa_store_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4081 struct gl_texture_image
*texImage
,
4082 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4083 GLint width
, GLint height
, GLint depth
,
4084 GLenum format
, GLenum type
, const void *pixels
,
4085 const struct gl_pixelstore_attrib
*packing
)
4087 store_texsubimage(ctx
, texImage
,
4088 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4089 format
, type
, pixels
, packing
, "glTexSubImage");
4094 * Fallback for Driver.CompressedTexImage()
4097 _mesa_store_compressed_teximage(struct gl_context
*ctx
, GLuint dims
,
4098 struct gl_texture_image
*texImage
,
4099 GLsizei imageSize
, const GLvoid
*data
)
4101 /* only 2D and 3D compressed images are supported at this time */
4103 _mesa_problem(ctx
, "Unexpected glCompressedTexImage1D call");
4107 /* This is pretty simple, because unlike the general texstore path we don't
4108 * have to worry about the usual image unpacking or image transfer
4112 ASSERT(texImage
->Width
> 0);
4113 ASSERT(texImage
->Height
> 0);
4114 ASSERT(texImage
->Depth
> 0);
4116 /* allocate storage for texture data */
4117 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
4118 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage%uD", dims
);
4122 _mesa_store_compressed_texsubimage(ctx
, dims
, texImage
,
4124 texImage
->Width
, texImage
->Height
, texImage
->Depth
,
4125 texImage
->TexFormat
,
4131 * Fallback for Driver.CompressedTexSubImage()
4134 _mesa_store_compressed_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4135 struct gl_texture_image
*texImage
,
4136 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4137 GLsizei width
, GLsizei height
, GLsizei depth
,
4139 GLsizei imageSize
, const GLvoid
*data
)
4141 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
4145 const gl_format texFormat
= texImage
->TexFormat
;
4150 _mesa_problem(ctx
, "Unexpected 1D compressed texsubimage call");
4154 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4156 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4157 data
= _mesa_validate_pbo_compressed_teximage(ctx
, dims
, imageSize
, data
,
4159 "glCompressedTexSubImage");
4163 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4164 src
= (const GLubyte
*) data
;
4166 for (slice
= 0; slice
< depth
; slice
++) {
4167 /* Map dest texture buffer */
4168 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
+ zoffset
,
4169 xoffset
, yoffset
, width
, height
,
4170 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4171 &dstMap
, &dstRowStride
);
4174 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4175 rows
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4177 /* copy rows of blocks */
4178 for (i
= 0; i
< rows
; i
++) {
4179 memcpy(dstMap
, src
, bytesPerRow
);
4180 dstMap
+= dstRowStride
;
4181 src
+= srcRowStride
;
4184 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ zoffset
);
4187 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage%uD",
4192 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);