2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
70 #include "texcompress_etc.h"
74 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
75 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
85 * Texture image storage function.
87 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
91 * Return GL_TRUE if the given image format is one that be converted
92 * to another format by swizzling.
95 can_swizzle(GLenum logicalBaseFormat
)
97 switch (logicalBaseFormat
) {
100 case GL_LUMINANCE_ALPHA
:
136 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
137 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
138 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
139 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
142 static const struct {
145 GLubyte from_rgba
[6];
146 } mappings
[MAX_IDX
] =
156 MAP4(ZERO
, ZERO
, ZERO
, 0),
186 MAP4(0, ZERO
, ZERO
, ONE
),
192 MAP4(ZERO
, 0, ZERO
, ONE
),
198 MAP4(ZERO
, ZERO
, 0, ONE
),
222 MAP4(0, 1, ZERO
, ONE
),
230 * Convert a GL image format enum to an IDX_* value (see above).
233 get_map_idx(GLenum value
)
236 case GL_LUMINANCE
: return IDX_LUMINANCE
;
237 case GL_ALPHA
: return IDX_ALPHA
;
238 case GL_INTENSITY
: return IDX_INTENSITY
;
239 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
240 case GL_RGB
: return IDX_RGB
;
241 case GL_RGBA
: return IDX_RGBA
;
242 case GL_RED
: return IDX_RED
;
243 case GL_GREEN
: return IDX_GREEN
;
244 case GL_BLUE
: return IDX_BLUE
;
245 case GL_BGR
: return IDX_BGR
;
246 case GL_BGRA
: return IDX_BGRA
;
247 case GL_ABGR_EXT
: return IDX_ABGR
;
248 case GL_RG
: return IDX_RG
;
250 _mesa_problem(NULL
, "Unexpected inFormat");
257 * When promoting texture formats (see below) we need to compute the
258 * mapping of dest components back to source components.
259 * This function does that.
260 * \param inFormat the incoming format of the texture
261 * \param outFormat the final texture format
262 * \return map[6] a full 6-component map
265 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
268 const int inFmt
= get_map_idx(inFormat
);
269 const int outFmt
= get_map_idx(outFormat
);
270 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
271 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
274 for (i
= 0; i
< 4; i
++)
275 map
[i
] = in2rgba
[rgba2out
[i
]];
281 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
282 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
283 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
295 * Make a temporary (color) texture image with GLfloat components.
296 * Apply all needed pixel unpacking and pixel transfer operations.
297 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
298 * Suppose the user specifies GL_LUMINANCE as the internal texture format
299 * but the graphics hardware doesn't support luminance textures. So, we might
300 * use an RGB hardware format instead.
301 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
303 * \param ctx the rendering context
304 * \param dims image dimensions: 1, 2 or 3
305 * \param logicalBaseFormat basic texture derived from the user's
306 * internal texture format value
307 * \param textureBaseFormat the actual basic format of the texture
308 * \param srcWidth source image width
309 * \param srcHeight source image height
310 * \param srcDepth source image depth
311 * \param srcFormat source image format
312 * \param srcType source image type
313 * \param srcAddr source image address
314 * \param srcPacking source image pixel packing
315 * \return resulting image with format = textureBaseFormat and type = GLfloat.
318 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
319 GLenum logicalBaseFormat
,
320 GLenum textureBaseFormat
,
321 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
322 GLenum srcFormat
, GLenum srcType
,
323 const GLvoid
*srcAddr
,
324 const struct gl_pixelstore_attrib
*srcPacking
,
325 GLbitfield transferOps
)
328 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
329 const GLint srcStride
=
330 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
334 ASSERT(dims
>= 1 && dims
<= 3);
336 ASSERT(logicalBaseFormat
== GL_RGBA
||
337 logicalBaseFormat
== GL_RGB
||
338 logicalBaseFormat
== GL_RG
||
339 logicalBaseFormat
== GL_RED
||
340 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
341 logicalBaseFormat
== GL_LUMINANCE
||
342 logicalBaseFormat
== GL_ALPHA
||
343 logicalBaseFormat
== GL_INTENSITY
||
344 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
346 ASSERT(textureBaseFormat
== GL_RGBA
||
347 textureBaseFormat
== GL_RGB
||
348 textureBaseFormat
== GL_RG
||
349 textureBaseFormat
== GL_RED
||
350 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
351 textureBaseFormat
== GL_LUMINANCE
||
352 textureBaseFormat
== GL_ALPHA
||
353 textureBaseFormat
== GL_INTENSITY
||
354 textureBaseFormat
== GL_DEPTH_COMPONENT
);
356 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
357 * components
* sizeof(GLfloat
));
362 for (img
= 0; img
< srcDepth
; img
++) {
364 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
368 for (row
= 0; row
< srcHeight
; row
++) {
369 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
370 dst
, srcFormat
, srcType
, src
,
371 srcPacking
, transferOps
);
372 dst
+= srcWidth
* components
;
377 if (logicalBaseFormat
!= textureBaseFormat
) {
379 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
380 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
385 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
386 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
387 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
389 /* The actual texture format should have at least as many components
390 * as the logical texture format.
392 ASSERT(texComponents
>= logComponents
);
394 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
395 * texComponents
* sizeof(GLfloat
));
401 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
403 n
= srcWidth
* srcHeight
* srcDepth
;
404 for (i
= 0; i
< n
; i
++) {
406 for (k
= 0; k
< texComponents
; k
++) {
409 newImage
[i
* texComponents
+ k
] = 0.0F
;
411 newImage
[i
* texComponents
+ k
] = 1.0F
;
413 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
418 tempImage
= newImage
;
426 * Make temporary image with uint pixel values. Used for unsigned
427 * integer-valued textures.
430 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
431 GLenum logicalBaseFormat
,
432 GLenum textureBaseFormat
,
433 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
434 GLenum srcFormat
, GLenum srcType
,
435 const GLvoid
*srcAddr
,
436 const struct gl_pixelstore_attrib
*srcPacking
)
439 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
440 const GLint srcStride
=
441 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
445 ASSERT(dims
>= 1 && dims
<= 3);
447 ASSERT(logicalBaseFormat
== GL_RGBA
||
448 logicalBaseFormat
== GL_RGB
||
449 logicalBaseFormat
== GL_RG
||
450 logicalBaseFormat
== GL_RED
||
451 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
452 logicalBaseFormat
== GL_LUMINANCE
||
453 logicalBaseFormat
== GL_INTENSITY
||
454 logicalBaseFormat
== GL_ALPHA
);
456 ASSERT(textureBaseFormat
== GL_RGBA
||
457 textureBaseFormat
== GL_RGB
||
458 textureBaseFormat
== GL_RG
||
459 textureBaseFormat
== GL_RED
||
460 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
461 textureBaseFormat
== GL_LUMINANCE
||
462 textureBaseFormat
== GL_INTENSITY
||
463 textureBaseFormat
== GL_ALPHA
);
465 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
466 * components
* sizeof(GLuint
));
471 for (img
= 0; img
< srcDepth
; img
++) {
473 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
477 for (row
= 0; row
< srcHeight
; row
++) {
478 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
479 dst
, srcFormat
, srcType
, src
,
481 dst
+= srcWidth
* components
;
486 if (logicalBaseFormat
!= textureBaseFormat
) {
488 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
489 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
494 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
495 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
496 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
498 /* The actual texture format should have at least as many components
499 * as the logical texture format.
501 ASSERT(texComponents
>= logComponents
);
503 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
504 * texComponents
* sizeof(GLuint
));
510 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
512 n
= srcWidth
* srcHeight
* srcDepth
;
513 for (i
= 0; i
< n
; i
++) {
515 for (k
= 0; k
< texComponents
; k
++) {
518 newImage
[i
* texComponents
+ k
] = 0;
520 newImage
[i
* texComponents
+ k
] = 1;
522 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
527 tempImage
= newImage
;
536 * Make a temporary (color) texture image with GLubyte components.
537 * Apply all needed pixel unpacking and pixel transfer operations.
538 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
539 * Suppose the user specifies GL_LUMINANCE as the internal texture format
540 * but the graphics hardware doesn't support luminance textures. So, we might
541 * use an RGB hardware format instead.
542 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
544 * \param ctx the rendering context
545 * \param dims image dimensions: 1, 2 or 3
546 * \param logicalBaseFormat basic texture derived from the user's
547 * internal texture format value
548 * \param textureBaseFormat the actual basic format of the texture
549 * \param srcWidth source image width
550 * \param srcHeight source image height
551 * \param srcDepth source image depth
552 * \param srcFormat source image format
553 * \param srcType source image type
554 * \param srcAddr source image address
555 * \param srcPacking source image pixel packing
556 * \return resulting image with format = textureBaseFormat and type = GLubyte.
559 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
560 GLenum logicalBaseFormat
,
561 GLenum textureBaseFormat
,
562 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
563 GLenum srcFormat
, GLenum srcType
,
564 const GLvoid
*srcAddr
,
565 const struct gl_pixelstore_attrib
*srcPacking
)
567 GLuint transferOps
= ctx
->_ImageTransferState
;
568 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
570 GLubyte
*tempImage
, *dst
;
572 ASSERT(dims
>= 1 && dims
<= 3);
574 ASSERT(logicalBaseFormat
== GL_RGBA
||
575 logicalBaseFormat
== GL_RGB
||
576 logicalBaseFormat
== GL_RG
||
577 logicalBaseFormat
== GL_RED
||
578 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
579 logicalBaseFormat
== GL_LUMINANCE
||
580 logicalBaseFormat
== GL_ALPHA
||
581 logicalBaseFormat
== GL_INTENSITY
);
583 ASSERT(textureBaseFormat
== GL_RGBA
||
584 textureBaseFormat
== GL_RGB
||
585 textureBaseFormat
== GL_RG
||
586 textureBaseFormat
== GL_RED
||
587 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
588 textureBaseFormat
== GL_LUMINANCE
||
589 textureBaseFormat
== GL_ALPHA
||
590 textureBaseFormat
== GL_INTENSITY
);
592 /* unpack and transfer the source image */
593 tempImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
594 * components
* sizeof(GLubyte
));
600 for (img
= 0; img
< srcDepth
; img
++) {
601 const GLint srcStride
=
602 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
604 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
608 for (row
= 0; row
< srcHeight
; row
++) {
609 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
610 srcFormat
, srcType
, src
, srcPacking
,
612 dst
+= srcWidth
* components
;
617 if (logicalBaseFormat
!= textureBaseFormat
) {
618 /* one more conversion step */
619 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
620 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
625 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
626 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
627 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
629 /* The actual texture format should have at least as many components
630 * as the logical texture format.
632 ASSERT(texComponents
>= logComponents
);
634 newImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
635 * texComponents
* sizeof(GLubyte
));
641 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
643 n
= srcWidth
* srcHeight
* srcDepth
;
644 for (i
= 0; i
< n
; i
++) {
646 for (k
= 0; k
< texComponents
; k
++) {
649 newImage
[i
* texComponents
+ k
] = 0;
651 newImage
[i
* texComponents
+ k
] = 255;
653 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
658 tempImage
= newImage
;
666 * Copy GLubyte pixels from <src> to <dst> with swizzling.
667 * \param dst destination pixels
668 * \param dstComponents number of color components in destination pixels
669 * \param src source pixels
670 * \param srcComponents number of color components in source pixels
671 * \param map the swizzle mapping. map[X] says where to find the X component
672 * in the source image's pixels. For example, if the source image
673 * is GL_BGRA and X = red, map[0] yields 2.
674 * \param count number of pixels to copy/swizzle.
677 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
678 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
680 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
683 for (i = 0; i < count; i++) { \
685 if (srcComps == 4) { \
686 COPY_4UBV(tmp, src); \
689 for (j = 0; j < srcComps; j++) { \
694 for (j = 0; j < dstComps; j++) { \
695 dst[j] = tmp[map[j]]; \
706 ASSERT(srcComponents
<= 4);
707 ASSERT(dstComponents
<= 4);
709 switch (dstComponents
) {
711 switch (srcComponents
) {
713 SWZ_CPY(dst
, src
, count
, 4, 4);
716 SWZ_CPY(dst
, src
, count
, 4, 3);
719 SWZ_CPY(dst
, src
, count
, 4, 2);
722 SWZ_CPY(dst
, src
, count
, 4, 1);
729 switch (srcComponents
) {
731 SWZ_CPY(dst
, src
, count
, 3, 4);
734 SWZ_CPY(dst
, src
, count
, 3, 3);
737 SWZ_CPY(dst
, src
, count
, 3, 2);
740 SWZ_CPY(dst
, src
, count
, 3, 1);
747 switch (srcComponents
) {
749 SWZ_CPY(dst
, src
, count
, 2, 4);
752 SWZ_CPY(dst
, src
, count
, 2, 3);
755 SWZ_CPY(dst
, src
, count
, 2, 2);
758 SWZ_CPY(dst
, src
, count
, 2, 1);
765 switch (srcComponents
) {
767 SWZ_CPY(dst
, src
, count
, 1, 4);
770 SWZ_CPY(dst
, src
, count
, 1, 3);
773 SWZ_CPY(dst
, src
, count
, 1, 2);
776 SWZ_CPY(dst
, src
, count
, 1, 1);
790 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
791 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
795 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
796 * mapping array depending on endianness.
798 static const GLubyte
*
799 type_mapping( GLenum srcType
)
803 case GL_UNSIGNED_BYTE
:
805 case GL_UNSIGNED_INT_8_8_8_8
:
806 return _mesa_little_endian() ? map_3210
: map_identity
;
807 case GL_UNSIGNED_INT_8_8_8_8_REV
:
808 return _mesa_little_endian() ? map_identity
: map_3210
;
816 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
817 * mapping array depending on pixelstore byte swapping state.
819 static const GLubyte
*
820 byteswap_mapping( GLboolean swapBytes
,
828 case GL_UNSIGNED_BYTE
:
830 case GL_UNSIGNED_INT_8_8_8_8
:
831 case GL_UNSIGNED_INT_8_8_8_8_REV
:
841 * Transfer a GLubyte texture image with component swizzling.
844 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
849 GLenum baseInternalFormat
,
851 const GLubyte
*rgba2dst
,
852 GLuint dstComponents
,
857 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
858 const GLvoid
*srcAddr
,
859 const struct gl_pixelstore_attrib
*srcPacking
)
861 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
862 const GLubyte
*srctype2ubyte
, *swap
;
863 GLubyte map
[4], src2base
[6], base2rgba
[6];
865 const GLint srcRowStride
=
866 _mesa_image_row_stride(srcPacking
, srcWidth
,
867 srcFormat
, GL_UNSIGNED_BYTE
);
868 const GLint srcImageStride
869 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
871 const GLubyte
*srcImage
872 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
873 srcWidth
, srcHeight
, srcFormat
,
874 GL_UNSIGNED_BYTE
, 0, 0, 0);
878 /* Translate from src->baseInternal->GL_RGBA->dst. This will
879 * correctly deal with RGBA->RGB->RGBA conversions where the final
880 * A value must be 0xff regardless of the incoming alpha values.
882 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
883 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
884 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
885 srctype2ubyte
= type_mapping(srcType
);
888 for (i
= 0; i
< 4; i
++)
889 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
891 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
893 if (srcComponents
== dstComponents
&&
894 srcRowStride
== dstRowStride
&&
895 srcRowStride
== srcWidth
* srcComponents
&&
897 /* 1 and 2D images only */
898 GLubyte
*dstImage
= dstSlices
[0];
899 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
900 srcWidth
* srcHeight
);
904 for (img
= 0; img
< srcDepth
; img
++) {
905 const GLubyte
*srcRow
= srcImage
;
906 GLubyte
*dstRow
= dstSlices
[img
];
907 for (row
= 0; row
< srcHeight
; row
++) {
908 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
909 dstRow
+= dstRowStride
;
910 srcRow
+= srcRowStride
;
912 srcImage
+= srcImageStride
;
919 * Teximage storage routine for when a simple memcpy will do.
920 * No pixel transfer operations or special texel encodings allowed.
921 * 1D, 2D and 3D images supported.
924 memcpy_texture(struct gl_context
*ctx
,
929 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
930 GLenum srcFormat
, GLenum srcType
,
931 const GLvoid
*srcAddr
,
932 const struct gl_pixelstore_attrib
*srcPacking
)
934 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
936 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
937 srcWidth
, srcHeight
, srcFormat
, srcType
);
938 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
939 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
940 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
941 const GLint bytesPerRow
= srcWidth
* texelBytes
;
943 if (dstRowStride
== srcRowStride
&&
944 dstRowStride
== bytesPerRow
) {
945 /* memcpy image by image */
947 for (img
= 0; img
< srcDepth
; img
++) {
948 GLubyte
*dstImage
= dstSlices
[img
];
949 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
950 srcImage
+= srcImageStride
;
954 /* memcpy row by row */
956 for (img
= 0; img
< srcDepth
; img
++) {
957 const GLubyte
*srcRow
= srcImage
;
958 GLubyte
*dstRow
= dstSlices
[img
];
959 for (row
= 0; row
< srcHeight
; row
++) {
960 memcpy(dstRow
, srcRow
, bytesPerRow
);
961 dstRow
+= dstRowStride
;
962 srcRow
+= srcRowStride
;
964 srcImage
+= srcImageStride
;
972 * Store a 32-bit integer or float depth component texture image.
975 _mesa_texstore_z32(TEXSTORE_PARAMS
)
977 const GLuint depthScale
= 0xffffffff;
980 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
981 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
982 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
984 if (dstFormat
== MESA_FORMAT_Z32
)
985 dstType
= GL_UNSIGNED_INT
;
989 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
990 ctx
->Pixel
.DepthBias
== 0.0f
&&
991 !srcPacking
->SwapBytes
&&
992 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
993 srcFormat
== GL_DEPTH_COMPONENT
&&
994 srcType
== dstType
) {
995 /* simple memcpy path */
996 memcpy_texture(ctx
, dims
,
998 dstRowStride
, dstSlices
,
999 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1000 srcAddr
, srcPacking
);
1005 for (img
= 0; img
< srcDepth
; img
++) {
1006 GLubyte
*dstRow
= dstSlices
[img
];
1007 for (row
= 0; row
< srcHeight
; row
++) {
1008 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1009 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1010 _mesa_unpack_depth_span(ctx
, srcWidth
,
1012 depthScale
, srcType
, src
, srcPacking
);
1013 dstRow
+= dstRowStride
;
1022 * Store a 24-bit integer depth component texture image.
1025 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1027 const GLuint depthScale
= 0xffffff;
1030 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1035 for (img
= 0; img
< srcDepth
; img
++) {
1036 GLubyte
*dstRow
= dstSlices
[img
];
1037 for (row
= 0; row
< srcHeight
; row
++) {
1038 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1039 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1040 _mesa_unpack_depth_span(ctx
, srcWidth
,
1041 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1042 depthScale
, srcType
, src
, srcPacking
);
1043 dstRow
+= dstRowStride
;
1052 * Store a 24-bit integer depth component texture image.
1055 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1057 const GLuint depthScale
= 0xffffff;
1060 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1065 for (img
= 0; img
< srcDepth
; img
++) {
1066 GLubyte
*dstRow
= dstSlices
[img
];
1067 for (row
= 0; row
< srcHeight
; row
++) {
1068 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1069 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1070 GLuint
*dst
= (GLuint
*) dstRow
;
1072 _mesa_unpack_depth_span(ctx
, srcWidth
,
1073 GL_UNSIGNED_INT
, dst
,
1074 depthScale
, srcType
, src
, srcPacking
);
1075 for (i
= 0; i
< srcWidth
; i
++)
1077 dstRow
+= dstRowStride
;
1086 * Store a 16-bit integer depth component texture image.
1089 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1091 const GLuint depthScale
= 0xffff;
1093 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1094 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1096 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1097 ctx
->Pixel
.DepthBias
== 0.0f
&&
1098 !srcPacking
->SwapBytes
&&
1099 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1100 srcFormat
== GL_DEPTH_COMPONENT
&&
1101 srcType
== GL_UNSIGNED_SHORT
) {
1102 /* simple memcpy path */
1103 memcpy_texture(ctx
, dims
,
1105 dstRowStride
, dstSlices
,
1106 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1107 srcAddr
, srcPacking
);
1112 for (img
= 0; img
< srcDepth
; img
++) {
1113 GLubyte
*dstRow
= dstSlices
[img
];
1114 for (row
= 0; row
< srcHeight
; row
++) {
1115 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1116 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1117 GLushort
*dst16
= (GLushort
*) dstRow
;
1118 _mesa_unpack_depth_span(ctx
, srcWidth
,
1119 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1120 srcType
, src
, srcPacking
);
1121 dstRow
+= dstRowStride
;
1130 * Store an rgb565 or rgb565_rev texture image.
1133 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1135 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1137 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1138 dstFormat
== MESA_FORMAT_RGB565_REV
);
1139 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1141 if (!ctx
->_ImageTransferState
&&
1142 baseInternalFormat
== GL_RGB
&&
1143 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1144 srcPacking
->SwapBytes
)) {
1145 /* simple memcpy path */
1146 memcpy_texture(ctx
, dims
,
1148 dstRowStride
, dstSlices
,
1149 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1150 srcAddr
, srcPacking
);
1152 else if (!ctx
->_ImageTransferState
&&
1153 !srcPacking
->SwapBytes
&&
1154 baseInternalFormat
== GL_RGB
&&
1155 srcFormat
== GL_RGB
&&
1156 srcType
== GL_UNSIGNED_BYTE
&&
1158 /* do optimized tex store */
1159 const GLint srcRowStride
=
1160 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1161 const GLubyte
*src
= (const GLubyte
*)
1162 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1163 srcFormat
, srcType
, 0, 0, 0);
1164 GLubyte
*dst
= dstSlices
[0];
1166 for (row
= 0; row
< srcHeight
; row
++) {
1167 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1168 GLushort
*dstUS
= (GLushort
*) dst
;
1169 /* check for byteswapped format */
1170 if (dstFormat
== MESA_FORMAT_RGB565
) {
1171 for (col
= 0; col
< srcWidth
; col
++) {
1172 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1177 for (col
= 0; col
< srcWidth
; col
++) {
1178 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1182 dst
+= dstRowStride
;
1183 src
+= srcRowStride
;
1188 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1191 srcWidth
, srcHeight
, srcDepth
,
1192 srcFormat
, srcType
, srcAddr
,
1194 const GLubyte
*src
= tempImage
;
1195 GLint img
, row
, col
;
1198 for (img
= 0; img
< srcDepth
; img
++) {
1199 GLubyte
*dstRow
= dstSlices
[img
];
1200 for (row
= 0; row
< srcHeight
; row
++) {
1201 GLushort
*dstUS
= (GLushort
*) dstRow
;
1202 /* check for byteswapped format */
1203 if (dstFormat
== MESA_FORMAT_RGB565
) {
1204 for (col
= 0; col
< srcWidth
; col
++) {
1205 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1212 for (col
= 0; col
< srcWidth
; col
++) {
1213 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1219 dstRow
+= dstRowStride
;
1222 free((void *) tempImage
);
1229 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1232 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1234 const GLboolean littleEndian
= _mesa_little_endian();
1235 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1237 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1238 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1239 dstFormat
== MESA_FORMAT_RGBX8888
||
1240 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1241 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1243 if (!ctx
->_ImageTransferState
&&
1244 baseInternalFormat
== GL_RGBA
&&
1245 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1246 srcPacking
->SwapBytes
)) {
1247 /* simple memcpy path */
1248 memcpy_texture(ctx
, dims
,
1250 dstRowStride
, dstSlices
,
1251 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1252 srcAddr
, srcPacking
);
1254 else if (!ctx
->_ImageTransferState
&&
1255 (srcType
== GL_UNSIGNED_BYTE
||
1256 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1257 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1258 can_swizzle(baseInternalFormat
) &&
1259 can_swizzle(srcFormat
)) {
1263 /* dstmap - how to swizzle from RGBA to dst format:
1265 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1266 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1267 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1268 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1281 _mesa_swizzle_ubyte_image(ctx
, dims
,
1286 dstRowStride
, dstSlices
,
1287 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1292 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1295 srcWidth
, srcHeight
, srcDepth
,
1296 srcFormat
, srcType
, srcAddr
,
1298 const GLubyte
*src
= tempImage
;
1299 GLint img
, row
, col
;
1302 for (img
= 0; img
< srcDepth
; img
++) {
1303 GLubyte
*dstRow
= dstSlices
[img
];
1304 for (row
= 0; row
< srcHeight
; row
++) {
1305 GLuint
*dstUI
= (GLuint
*) dstRow
;
1306 if (dstFormat
== MESA_FORMAT_RGBA8888
||
1307 dstFormat
== MESA_FORMAT_RGBX8888
) {
1308 for (col
= 0; col
< srcWidth
; col
++) {
1309 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1317 for (col
= 0; col
< srcWidth
; col
++) {
1318 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1325 dstRow
+= dstRowStride
;
1328 free((void *) tempImage
);
1335 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1337 const GLboolean littleEndian
= _mesa_little_endian();
1338 const GLenum baseFormat
= GL_RGBA
;
1340 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1341 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1342 dstFormat
== MESA_FORMAT_XRGB8888
||
1343 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1344 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1346 if (!ctx
->_ImageTransferState
&&
1347 baseInternalFormat
== GL_RGBA
&&
1348 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1349 srcPacking
->SwapBytes
)) {
1350 /* simple memcpy path (big endian) */
1351 memcpy_texture(ctx
, dims
,
1353 dstRowStride
, dstSlices
,
1354 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1355 srcAddr
, srcPacking
);
1357 else if (!ctx
->_ImageTransferState
&&
1358 !srcPacking
->SwapBytes
&&
1359 (dstFormat
== MESA_FORMAT_ARGB8888
||
1360 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1361 srcFormat
== GL_RGB
&&
1362 (baseInternalFormat
== GL_RGBA
||
1363 baseInternalFormat
== GL_RGB
) &&
1364 srcType
== GL_UNSIGNED_BYTE
) {
1366 for (img
= 0; img
< srcDepth
; img
++) {
1367 const GLint srcRowStride
=
1368 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1369 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1370 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1371 GLubyte
*dstRow
= dstSlices
[img
];
1372 for (row
= 0; row
< srcHeight
; row
++) {
1373 GLuint
*d4
= (GLuint
*) dstRow
;
1374 for (col
= 0; col
< srcWidth
; col
++) {
1375 d4
[col
] = PACK_COLOR_8888(0xff,
1376 srcRow
[col
* 3 + RCOMP
],
1377 srcRow
[col
* 3 + GCOMP
],
1378 srcRow
[col
* 3 + BCOMP
]);
1380 dstRow
+= dstRowStride
;
1381 srcRow
+= srcRowStride
;
1385 else if (!ctx
->_ImageTransferState
&&
1386 !srcPacking
->SwapBytes
&&
1387 dstFormat
== MESA_FORMAT_ARGB8888
&&
1388 srcFormat
== GL_RGBA
&&
1389 baseInternalFormat
== GL_RGBA
&&
1390 srcType
== GL_UNSIGNED_BYTE
) {
1391 /* same as above case, but src data has alpha too */
1392 GLint img
, row
, col
;
1393 /* For some reason, streaming copies to write-combined regions
1394 * are extremely sensitive to the characteristics of how the
1395 * source data is retrieved. By reordering the source reads to
1396 * be in-order, the speed of this operation increases by half.
1397 * Strangely the same isn't required for the RGB path, above.
1399 for (img
= 0; img
< srcDepth
; img
++) {
1400 const GLint srcRowStride
=
1401 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1402 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1403 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1404 GLubyte
*dstRow
= dstSlices
[img
];
1405 for (row
= 0; row
< srcHeight
; row
++) {
1406 GLuint
*d4
= (GLuint
*) dstRow
;
1407 for (col
= 0; col
< srcWidth
; col
++) {
1408 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1409 srcRow
[col
* 4 + RCOMP
],
1410 srcRow
[col
* 4 + GCOMP
],
1411 srcRow
[col
* 4 + BCOMP
]);
1413 dstRow
+= dstRowStride
;
1414 srcRow
+= srcRowStride
;
1418 else if (!ctx
->_ImageTransferState
&&
1419 (srcType
== GL_UNSIGNED_BYTE
||
1420 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1421 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1422 can_swizzle(baseInternalFormat
) &&
1423 can_swizzle(srcFormat
)) {
1427 /* dstmap - how to swizzle from RGBA to dst format:
1429 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1430 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1431 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1432 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1433 dstmap
[3] = 3; /* alpha */
1434 dstmap
[2] = 0; /* red */
1435 dstmap
[1] = 1; /* green */
1436 dstmap
[0] = 2; /* blue */
1439 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1440 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1441 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1442 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1449 _mesa_swizzle_ubyte_image(ctx
, dims
,
1456 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1461 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1464 srcWidth
, srcHeight
, srcDepth
,
1465 srcFormat
, srcType
, srcAddr
,
1467 const GLubyte
*src
= tempImage
;
1468 GLint img
, row
, col
;
1471 for (img
= 0; img
< srcDepth
; img
++) {
1472 GLubyte
*dstRow
= dstSlices
[img
];
1473 for (row
= 0; row
< srcHeight
; row
++) {
1474 GLuint
*dstUI
= (GLuint
*) dstRow
;
1475 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1476 for (col
= 0; col
< srcWidth
; col
++) {
1477 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1484 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1485 for (col
= 0; col
< srcWidth
; col
++) {
1486 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1494 for (col
= 0; col
< srcWidth
; col
++) {
1495 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1502 dstRow
+= dstRowStride
;
1505 free((void *) tempImage
);
1512 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1514 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1516 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1517 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1519 if (!ctx
->_ImageTransferState
&&
1520 baseInternalFormat
== GL_RGB
&&
1521 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1522 srcPacking
->SwapBytes
)) {
1523 /* simple memcpy path */
1524 memcpy_texture(ctx
, dims
,
1526 dstRowStride
, dstSlices
,
1527 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1528 srcAddr
, srcPacking
);
1530 else if (!ctx
->_ImageTransferState
&&
1531 !srcPacking
->SwapBytes
&&
1532 srcFormat
== GL_RGBA
&&
1533 srcType
== GL_UNSIGNED_BYTE
) {
1534 /* extract RGB from RGBA */
1535 GLint img
, row
, col
;
1536 for (img
= 0; img
< srcDepth
; img
++) {
1537 const GLint srcRowStride
=
1538 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1539 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1540 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1541 GLubyte
*dstRow
= dstSlices
[img
];
1542 for (row
= 0; row
< srcHeight
; row
++) {
1543 for (col
= 0; col
< srcWidth
; col
++) {
1544 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1545 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1546 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1548 dstRow
+= dstRowStride
;
1549 srcRow
+= srcRowStride
;
1553 else if (!ctx
->_ImageTransferState
&&
1554 srcType
== GL_UNSIGNED_BYTE
&&
1555 can_swizzle(baseInternalFormat
) &&
1556 can_swizzle(srcFormat
)) {
1560 /* dstmap - how to swizzle from RGBA to dst format:
1565 dstmap
[3] = ONE
; /* ? */
1567 _mesa_swizzle_ubyte_image(ctx
, dims
,
1572 dstRowStride
, dstSlices
,
1573 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1578 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1581 srcWidth
, srcHeight
, srcDepth
,
1582 srcFormat
, srcType
, srcAddr
,
1584 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1585 GLint img
, row
, col
;
1588 for (img
= 0; img
< srcDepth
; img
++) {
1589 GLubyte
*dstRow
= dstSlices
[img
];
1590 for (row
= 0; row
< srcHeight
; row
++) {
1593 for (col
= 0; col
< srcWidth
; col
++) {
1594 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1595 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1596 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1601 for (col
= 0; col
< srcWidth
; col
++) {
1602 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1603 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1604 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1609 for (col
= 0; col
< srcWidth
; col
++) {
1610 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1611 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1612 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1616 dstRow
+= dstRowStride
;
1619 free((void *) tempImage
);
1626 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1628 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1630 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1631 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1633 if (!ctx
->_ImageTransferState
&&
1634 baseInternalFormat
== GL_RGB
&&
1635 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1636 srcPacking
->SwapBytes
)) {
1637 /* simple memcpy path */
1638 memcpy_texture(ctx
, dims
,
1640 dstRowStride
, dstSlices
,
1641 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1642 srcAddr
, srcPacking
);
1644 else if (!ctx
->_ImageTransferState
&&
1645 !srcPacking
->SwapBytes
&&
1646 srcFormat
== GL_RGBA
&&
1647 srcType
== GL_UNSIGNED_BYTE
) {
1648 /* extract BGR from RGBA */
1650 for (img
= 0; img
< srcDepth
; img
++) {
1651 const GLint srcRowStride
=
1652 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1653 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1654 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1655 GLubyte
*dstRow
= dstSlices
[img
];
1656 for (row
= 0; row
< srcHeight
; row
++) {
1657 for (col
= 0; col
< srcWidth
; col
++) {
1658 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1659 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1660 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1662 dstRow
+= dstRowStride
;
1663 srcRow
+= srcRowStride
;
1667 else if (!ctx
->_ImageTransferState
&&
1668 srcType
== GL_UNSIGNED_BYTE
&&
1669 can_swizzle(baseInternalFormat
) &&
1670 can_swizzle(srcFormat
)) {
1674 /* dstmap - how to swizzle from RGBA to dst format:
1679 dstmap
[3] = ONE
; /* ? */
1681 _mesa_swizzle_ubyte_image(ctx
, dims
,
1686 dstRowStride
, dstSlices
,
1687 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1692 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1695 srcWidth
, srcHeight
, srcDepth
,
1696 srcFormat
, srcType
, srcAddr
,
1698 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1699 GLint img
, row
, col
;
1702 for (img
= 0; img
< srcDepth
; img
++) {
1703 GLubyte
*dstRow
= dstSlices
[img
];
1704 for (row
= 0; row
< srcHeight
; row
++) {
1705 for (col
= 0; col
< srcWidth
; col
++) {
1706 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1707 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1708 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1711 dstRow
+= dstRowStride
;
1714 free((void *) tempImage
);
1721 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1723 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1725 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1726 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1727 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1729 if (!ctx
->_ImageTransferState
&&
1730 baseInternalFormat
== GL_RGBA
&&
1731 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1732 srcPacking
->SwapBytes
)) {
1733 /* simple memcpy path */
1734 memcpy_texture(ctx
, dims
,
1736 dstRowStride
, dstSlices
,
1737 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1738 srcAddr
, srcPacking
);
1742 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1745 srcWidth
, srcHeight
, srcDepth
,
1746 srcFormat
, srcType
, srcAddr
,
1748 const GLubyte
*src
= tempImage
;
1749 GLint img
, row
, col
;
1752 for (img
= 0; img
< srcDepth
; img
++) {
1753 GLubyte
*dstRow
= dstSlices
[img
];
1754 for (row
= 0; row
< srcHeight
; row
++) {
1755 GLushort
*dstUS
= (GLushort
*) dstRow
;
1756 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1757 for (col
= 0; col
< srcWidth
; col
++) {
1758 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1766 for (col
= 0; col
< srcWidth
; col
++) {
1767 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1774 dstRow
+= dstRowStride
;
1777 free((void *) tempImage
);
1783 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1785 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1787 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1788 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1790 if (!ctx
->_ImageTransferState
&&
1791 baseInternalFormat
== GL_RGBA
&&
1792 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1793 srcPacking
->SwapBytes
)) {
1794 /* simple memcpy path */
1795 memcpy_texture(ctx
, dims
,
1797 dstRowStride
, dstSlices
,
1798 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1799 srcAddr
, srcPacking
);
1803 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1806 srcWidth
, srcHeight
, srcDepth
,
1807 srcFormat
, srcType
, srcAddr
,
1809 const GLubyte
*src
=tempImage
;
1810 GLint img
, row
, col
;
1813 for (img
= 0; img
< srcDepth
; img
++) {
1814 GLubyte
*dstRow
= dstSlices
[img
];
1815 for (row
= 0; row
< srcHeight
; row
++) {
1816 GLushort
*dstUS
= (GLushort
*) dstRow
;
1817 for (col
= 0; col
< srcWidth
; col
++) {
1818 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1824 dstRow
+= dstRowStride
;
1827 free((void *) tempImage
);
1833 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1835 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1837 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1838 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1839 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1841 if (!ctx
->_ImageTransferState
&&
1842 baseInternalFormat
== GL_RGBA
&&
1843 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1844 srcPacking
->SwapBytes
)) {
1845 /* simple memcpy path */
1846 memcpy_texture(ctx
, dims
,
1848 dstRowStride
, dstSlices
,
1849 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1850 srcAddr
, srcPacking
);
1854 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1857 srcWidth
, srcHeight
, srcDepth
,
1858 srcFormat
, srcType
, srcAddr
,
1860 const GLubyte
*src
=tempImage
;
1861 GLint img
, row
, col
;
1864 for (img
= 0; img
< srcDepth
; img
++) {
1865 GLubyte
*dstRow
= dstSlices
[img
];
1866 for (row
= 0; row
< srcHeight
; row
++) {
1867 GLushort
*dstUS
= (GLushort
*) dstRow
;
1868 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1869 for (col
= 0; col
< srcWidth
; col
++) {
1870 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
1878 for (col
= 0; col
< srcWidth
; col
++) {
1879 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
1886 dstRow
+= dstRowStride
;
1889 free((void *) tempImage
);
1896 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1898 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1900 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
1901 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1903 if (!ctx
->_ImageTransferState
&&
1904 baseInternalFormat
== GL_RGBA
&&
1905 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1906 srcPacking
->SwapBytes
)) {
1907 /* simple memcpy path */
1908 memcpy_texture(ctx
, dims
,
1910 dstRowStride
, dstSlices
,
1911 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1912 srcAddr
, srcPacking
);
1916 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1919 srcWidth
, srcHeight
, srcDepth
,
1920 srcFormat
, srcType
, srcAddr
,
1922 ctx
->_ImageTransferState
);
1923 const GLfloat
*src
= tempImage
;
1924 GLint img
, row
, col
;
1927 for (img
= 0; img
< srcDepth
; img
++) {
1928 GLubyte
*dstRow
= dstSlices
[img
];
1929 if (baseInternalFormat
== GL_RGBA
) {
1930 for (row
= 0; row
< srcHeight
; row
++) {
1931 GLuint
*dstUI
= (GLuint
*) dstRow
;
1932 for (col
= 0; col
< srcWidth
; col
++) {
1935 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1936 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1937 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1938 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1939 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1942 dstRow
+= dstRowStride
;
1944 } else if (baseInternalFormat
== GL_RGB
) {
1945 for (row
= 0; row
< srcHeight
; row
++) {
1946 GLuint
*dstUI
= (GLuint
*) dstRow
;
1947 for (col
= 0; col
< srcWidth
; col
++) {
1950 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1951 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1952 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1953 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
1956 dstRow
+= dstRowStride
;
1962 free((void *) tempImage
);
1969 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1972 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1974 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1976 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
1977 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1981 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1984 srcWidth
, srcHeight
, srcDepth
,
1985 srcFormat
, srcType
, srcAddr
,
1987 const GLubyte
*src
= tempImage
;
1988 GLint img
, row
, col
;
1991 for (img
= 0; img
< srcDepth
; img
++) {
1992 GLubyte
*dstRow
= dstSlices
[img
];
1993 for (row
= 0; row
< srcHeight
; row
++) {
1994 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1995 for (col
= 0; col
< srcWidth
; col
++) {
1996 /* src[0] is luminance, src[1] is alpha */
1997 dstUS
[col
] = PACK_COLOR_44( src
[1],
2001 dstRow
+= dstRowStride
;
2004 free((void *) tempImage
);
2011 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2014 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2016 const GLboolean littleEndian
= _mesa_little_endian();
2017 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2019 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2020 dstFormat
== MESA_FORMAT_AL88_REV
||
2021 dstFormat
== MESA_FORMAT_GR88
||
2022 dstFormat
== MESA_FORMAT_RG88
);
2023 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2025 if (!ctx
->_ImageTransferState
&&
2026 !srcPacking
->SwapBytes
&&
2027 ((dstFormat
== MESA_FORMAT_AL88
&&
2028 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2029 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2030 (dstFormat
== MESA_FORMAT_GR88
&&
2031 baseInternalFormat
== srcFormat
)) &&
2032 srcType
== GL_UNSIGNED_BYTE
&&
2034 /* simple memcpy path */
2035 memcpy_texture(ctx
, dims
,
2037 dstRowStride
, dstSlices
,
2038 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2039 srcAddr
, srcPacking
);
2041 else if (!ctx
->_ImageTransferState
&&
2043 srcType
== GL_UNSIGNED_BYTE
&&
2044 can_swizzle(baseInternalFormat
) &&
2045 can_swizzle(srcFormat
)) {
2048 /* dstmap - how to swizzle from RGBA to dst format:
2050 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2051 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2052 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2062 if ((littleEndian
&& dstFormat
== MESA_FORMAT_GR88
) ||
2063 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88
)) {
2072 dstmap
[2] = ZERO
; /* ? */
2073 dstmap
[3] = ONE
; /* ? */
2075 _mesa_swizzle_ubyte_image(ctx
, dims
,
2080 dstRowStride
, dstSlices
,
2081 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2086 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2089 srcWidth
, srcHeight
, srcDepth
,
2090 srcFormat
, srcType
, srcAddr
,
2092 const GLubyte
*src
= tempImage
;
2093 GLint img
, row
, col
;
2096 for (img
= 0; img
< srcDepth
; img
++) {
2097 GLubyte
*dstRow
= dstSlices
[img
];
2098 for (row
= 0; row
< srcHeight
; row
++) {
2099 GLushort
*dstUS
= (GLushort
*) dstRow
;
2100 if (dstFormat
== MESA_FORMAT_AL88
||
2101 dstFormat
== MESA_FORMAT_GR88
) {
2102 for (col
= 0; col
< srcWidth
; col
++) {
2103 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2104 dstUS
[col
] = PACK_COLOR_88( src
[1],
2110 for (col
= 0; col
< srcWidth
; col
++) {
2111 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2112 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2117 dstRow
+= dstRowStride
;
2120 free((void *) tempImage
);
2127 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2130 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2132 const GLboolean littleEndian
= _mesa_little_endian();
2133 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2135 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2136 dstFormat
== MESA_FORMAT_AL1616_REV
||
2137 dstFormat
== MESA_FORMAT_RG1616
||
2138 dstFormat
== MESA_FORMAT_RG1616_REV
);
2139 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2141 if (!ctx
->_ImageTransferState
&&
2142 !srcPacking
->SwapBytes
&&
2143 ((dstFormat
== MESA_FORMAT_AL1616
&&
2144 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2145 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2146 (dstFormat
== MESA_FORMAT_RG1616
&&
2147 baseInternalFormat
== srcFormat
)) &&
2148 srcType
== GL_UNSIGNED_SHORT
&&
2150 /* simple memcpy path */
2151 memcpy_texture(ctx
, dims
,
2153 dstRowStride
, dstSlices
,
2154 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2155 srcAddr
, srcPacking
);
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 GLubyte
*dstRow
= dstSlices
[img
];
2172 for (row
= 0; row
< srcHeight
; row
++) {
2173 GLuint
*dstUI
= (GLuint
*) dstRow
;
2174 if (dstFormat
== MESA_FORMAT_AL1616
||
2175 dstFormat
== MESA_FORMAT_RG1616
) {
2176 for (col
= 0; col
< srcWidth
; col
++) {
2179 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2180 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2181 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2186 for (col
= 0; col
< srcWidth
; col
++) {
2189 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2190 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2191 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2195 dstRow
+= dstRowStride
;
2198 free((void *) tempImage
);
2204 /* Texstore for R16, A16, L16, I16. */
2206 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2208 const GLboolean littleEndian
= _mesa_little_endian();
2209 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2211 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2212 dstFormat
== MESA_FORMAT_A16
||
2213 dstFormat
== MESA_FORMAT_L16
||
2214 dstFormat
== MESA_FORMAT_I16
);
2215 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2217 if (!ctx
->_ImageTransferState
&&
2218 !srcPacking
->SwapBytes
&&
2219 baseInternalFormat
== srcFormat
&&
2220 srcType
== GL_UNSIGNED_SHORT
&&
2222 /* simple memcpy path */
2223 memcpy_texture(ctx
, dims
,
2225 dstRowStride
, dstSlices
,
2226 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2227 srcAddr
, srcPacking
);
2231 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2234 srcWidth
, srcHeight
, srcDepth
,
2235 srcFormat
, srcType
, srcAddr
,
2237 ctx
->_ImageTransferState
);
2238 const GLfloat
*src
= tempImage
;
2239 GLint img
, row
, col
;
2242 for (img
= 0; img
< srcDepth
; img
++) {
2243 GLubyte
*dstRow
= dstSlices
[img
];
2244 for (row
= 0; row
< srcHeight
; row
++) {
2245 GLushort
*dstUS
= (GLushort
*) dstRow
;
2246 for (col
= 0; col
< srcWidth
; col
++) {
2249 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2253 dstRow
+= dstRowStride
;
2256 free((void *) tempImage
);
2263 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2265 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2267 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2268 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
2270 if (!ctx
->_ImageTransferState
&&
2271 !srcPacking
->SwapBytes
&&
2272 baseInternalFormat
== GL_RGBA
&&
2273 srcFormat
== GL_RGBA
&&
2274 srcType
== GL_UNSIGNED_SHORT
) {
2275 /* simple memcpy path */
2276 memcpy_texture(ctx
, dims
,
2278 dstRowStride
, dstSlices
,
2279 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2280 srcAddr
, srcPacking
);
2284 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2287 srcWidth
, srcHeight
, srcDepth
,
2288 srcFormat
, srcType
, srcAddr
,
2290 ctx
->_ImageTransferState
);
2291 const GLfloat
*src
= tempImage
;
2292 GLint img
, row
, col
;
2295 for (img
= 0; img
< srcDepth
; img
++) {
2296 GLubyte
*dstRow
= dstSlices
[img
];
2297 for (row
= 0; row
< srcHeight
; row
++) {
2298 GLushort
*dstUS
= (GLushort
*) dstRow
;
2299 for (col
= 0; col
< srcWidth
; col
++) {
2300 GLushort r
, g
, b
, a
;
2302 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2303 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2304 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2305 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2312 dstRow
+= dstRowStride
;
2315 free((void *) tempImage
);
2322 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2324 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2326 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2327 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2329 if (!ctx
->_ImageTransferState
&&
2330 !srcPacking
->SwapBytes
&&
2331 baseInternalFormat
== GL_RGBA
&&
2332 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2333 srcFormat
== GL_RGBA
&&
2334 srcType
== GL_SHORT
) {
2335 /* simple memcpy path */
2336 memcpy_texture(ctx
, dims
,
2338 dstRowStride
, dstSlices
,
2339 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2340 srcAddr
, srcPacking
);
2344 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2347 srcWidth
, srcHeight
, srcDepth
,
2348 srcFormat
, srcType
, srcAddr
,
2350 ctx
->_ImageTransferState
);
2351 const GLfloat
*src
= tempImage
;
2352 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2353 GLint img
, row
, col
;
2358 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2359 * 3 or 4 components/pixel here.
2361 for (img
= 0; img
< srcDepth
; img
++) {
2362 GLubyte
*dstRow
= dstSlices
[img
];
2363 for (row
= 0; row
< srcHeight
; row
++) {
2364 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2365 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2366 for (col
= 0; col
< srcWidth
; col
++) {
2368 for (c
= 0; c
< comps
; c
++) {
2370 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2371 dstRowS
[col
* comps
+ c
] = p
;
2374 dstRow
+= dstRowStride
;
2375 src
+= 4 * srcWidth
;
2377 for (col
= 0; col
< srcWidth
; col
++) {
2379 for (c
= 0; c
< comps
; c
++) {
2381 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2382 dstRowS
[col
* comps
+ c
] = p
;
2385 dstRow
+= dstRowStride
;
2386 src
+= 3 * srcWidth
;
2390 free((void *) tempImage
);
2397 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2399 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2401 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2402 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2404 if (!ctx
->_ImageTransferState
&&
2405 baseInternalFormat
== GL_RGB
&&
2406 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
2407 srcPacking
->SwapBytes
)) {
2408 /* simple memcpy path */
2409 memcpy_texture(ctx
, dims
,
2411 dstRowStride
, dstSlices
,
2412 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2413 srcAddr
, srcPacking
);
2417 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2420 srcWidth
, srcHeight
, srcDepth
,
2421 srcFormat
, srcType
, srcAddr
,
2423 const GLubyte
*src
= tempImage
;
2424 GLint img
, row
, col
;
2427 for (img
= 0; img
< srcDepth
; img
++) {
2428 GLubyte
*dstRow
= dstSlices
[img
];
2429 for (row
= 0; row
< srcHeight
; row
++) {
2430 for (col
= 0; col
< srcWidth
; col
++) {
2431 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2436 dstRow
+= dstRowStride
;
2439 free((void *) tempImage
);
2446 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2449 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2451 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2453 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2454 dstFormat
== MESA_FORMAT_L8
||
2455 dstFormat
== MESA_FORMAT_I8
||
2456 dstFormat
== MESA_FORMAT_R8
);
2457 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2459 if (!ctx
->_ImageTransferState
&&
2460 !srcPacking
->SwapBytes
&&
2461 baseInternalFormat
== srcFormat
&&
2462 srcType
== GL_UNSIGNED_BYTE
) {
2463 /* simple memcpy path */
2464 memcpy_texture(ctx
, dims
,
2466 dstRowStride
, dstSlices
,
2467 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2468 srcAddr
, srcPacking
);
2470 else if (!ctx
->_ImageTransferState
&&
2471 srcType
== GL_UNSIGNED_BYTE
&&
2472 can_swizzle(baseInternalFormat
) &&
2473 can_swizzle(srcFormat
)) {
2476 /* dstmap - how to swizzle from RGBA to dst format:
2478 if (dstFormat
== MESA_FORMAT_A8
) {
2484 dstmap
[1] = ZERO
; /* ? */
2485 dstmap
[2] = ZERO
; /* ? */
2486 dstmap
[3] = ONE
; /* ? */
2488 _mesa_swizzle_ubyte_image(ctx
, dims
,
2493 dstRowStride
, dstSlices
,
2494 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2499 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2502 srcWidth
, srcHeight
, srcDepth
,
2503 srcFormat
, srcType
, srcAddr
,
2505 const GLubyte
*src
= tempImage
;
2506 GLint img
, row
, col
;
2509 for (img
= 0; img
< srcDepth
; img
++) {
2510 GLubyte
*dstRow
= dstSlices
[img
];
2511 for (row
= 0; row
< srcHeight
; row
++) {
2512 for (col
= 0; col
< srcWidth
; col
++) {
2513 dstRow
[col
] = src
[col
];
2515 dstRow
+= dstRowStride
;
2519 free((void *) tempImage
);
2527 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2530 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2532 const GLboolean littleEndian
= _mesa_little_endian();
2534 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2536 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2537 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2538 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2539 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2540 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2541 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2542 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2543 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2545 /* always just memcpy since no pixel transfer ops apply */
2546 memcpy_texture(ctx
, dims
,
2548 dstRowStride
, dstSlices
,
2549 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2550 srcAddr
, srcPacking
);
2552 /* Check if we need byte swapping */
2553 /* XXX the logic here _might_ be wrong */
2554 if (srcPacking
->SwapBytes
^
2555 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2556 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2559 for (img
= 0; img
< srcDepth
; img
++) {
2560 GLubyte
*dstRow
= dstSlices
[img
];
2561 for (row
= 0; row
< srcHeight
; row
++) {
2562 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2563 dstRow
+= dstRowStride
;
2571 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2573 const GLboolean littleEndian
= _mesa_little_endian();
2574 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2576 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2577 ASSERT(texelBytes
== 2);
2578 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2579 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2580 (srcFormat
== GL_DUDV_ATI
));
2581 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2583 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2585 /* simple memcpy path */
2586 memcpy_texture(ctx
, dims
,
2588 dstRowStride
, dstSlices
,
2589 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2590 srcAddr
, srcPacking
);
2592 else if (srcType
== GL_BYTE
) {
2595 /* dstmap - how to swizzle from RGBA to dst format:
2605 dstmap
[2] = ZERO
; /* ? */
2606 dstmap
[3] = ONE
; /* ? */
2608 _mesa_swizzle_ubyte_image(ctx
, dims
,
2609 GL_LUMINANCE_ALPHA
, /* hack */
2610 GL_UNSIGNED_BYTE
, /* hack */
2611 GL_LUMINANCE_ALPHA
, /* hack */
2613 dstRowStride
, dstSlices
,
2614 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2618 /* general path - note this is defined for 2d textures only */
2619 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2620 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2621 srcFormat
, srcType
);
2622 GLbyte
*tempImage
, *dst
, *src
;
2625 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2626 * components
* sizeof(GLbyte
));
2630 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2631 srcWidth
, srcHeight
,
2636 for (row
= 0; row
< srcHeight
; row
++) {
2637 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2638 dst
, srcFormat
, srcType
, src
,
2640 dst
+= srcWidth
* components
;
2645 dst
= (GLbyte
*) dstSlices
[0];
2646 for (row
= 0; row
< srcHeight
; row
++) {
2647 memcpy(dst
, src
, srcWidth
* texelBytes
);
2648 dst
+= dstRowStride
;
2649 src
+= srcWidth
* texelBytes
;
2651 free((void *) tempImage
);
2658 * Store a texture in a signed normalized 8-bit format.
2661 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2663 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2665 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2666 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2667 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2668 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2669 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2671 if (!ctx
->_ImageTransferState
&&
2672 !srcPacking
->SwapBytes
&&
2673 baseInternalFormat
== srcFormat
&&
2674 srcType
== GL_BYTE
) {
2675 /* simple memcpy path */
2676 memcpy_texture(ctx
, dims
,
2678 dstRowStride
, dstSlices
,
2679 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2680 srcAddr
, srcPacking
);
2684 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2687 srcWidth
, srcHeight
, srcDepth
,
2688 srcFormat
, srcType
, srcAddr
,
2690 ctx
->_ImageTransferState
);
2691 const GLfloat
*src
= tempImage
;
2692 GLint img
, row
, col
;
2695 for (img
= 0; img
< srcDepth
; img
++) {
2696 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2697 for (row
= 0; row
< srcHeight
; row
++) {
2698 for (col
= 0; col
< srcWidth
; col
++) {
2699 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2701 dstRow
+= dstRowStride
;
2705 free((void *) tempImage
);
2712 * Store a texture in a signed normalized two-channel 16-bit format.
2715 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2717 const GLboolean littleEndian
= _mesa_little_endian();
2718 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2720 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2721 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2722 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2724 if (!ctx
->_ImageTransferState
&&
2725 !srcPacking
->SwapBytes
&&
2726 baseInternalFormat
== srcFormat
&&
2727 srcType
== GL_BYTE
&&
2729 /* simple memcpy path */
2730 memcpy_texture(ctx
, dims
,
2732 dstRowStride
, dstSlices
,
2733 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2734 srcAddr
, srcPacking
);
2738 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2741 srcWidth
, srcHeight
, srcDepth
,
2742 srcFormat
, srcType
, srcAddr
,
2744 ctx
->_ImageTransferState
);
2745 const GLfloat
*src
= tempImage
;
2746 GLint img
, row
, col
;
2749 for (img
= 0; img
< srcDepth
; img
++) {
2750 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2751 for (row
= 0; row
< srcHeight
; row
++) {
2752 GLbyte
*dst
= dstRow
;
2753 for (col
= 0; col
< srcWidth
; col
++) {
2754 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2755 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2759 dstRow
+= dstRowStride
;
2762 free((void *) tempImage
);
2767 /* Texstore for signed R16, A16, L16, I16. */
2769 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2771 const GLboolean littleEndian
= _mesa_little_endian();
2772 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2774 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2775 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2776 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2777 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2778 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2780 if (!ctx
->_ImageTransferState
&&
2781 !srcPacking
->SwapBytes
&&
2782 baseInternalFormat
== srcFormat
&&
2783 srcType
== GL_SHORT
&&
2785 /* simple memcpy path */
2786 memcpy_texture(ctx
, dims
,
2788 dstRowStride
, dstSlices
,
2789 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2790 srcAddr
, srcPacking
);
2794 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2797 srcWidth
, srcHeight
, srcDepth
,
2798 srcFormat
, srcType
, srcAddr
,
2800 ctx
->_ImageTransferState
);
2801 const GLfloat
*src
= tempImage
;
2802 GLint img
, row
, col
;
2805 for (img
= 0; img
< srcDepth
; img
++) {
2806 GLubyte
*dstRow
= dstSlices
[img
];
2807 for (row
= 0; row
< srcHeight
; row
++) {
2808 GLshort
*dstUS
= (GLshort
*) dstRow
;
2809 for (col
= 0; col
< srcWidth
; col
++) {
2812 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2816 dstRow
+= dstRowStride
;
2819 free((void *) tempImage
);
2825 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2828 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2830 const GLboolean littleEndian
= _mesa_little_endian();
2831 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2833 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2834 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2835 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2837 if (!ctx
->_ImageTransferState
&&
2838 !srcPacking
->SwapBytes
&&
2839 baseInternalFormat
== srcFormat
&&
2840 srcType
== GL_SHORT
&&
2842 /* simple memcpy path */
2843 memcpy_texture(ctx
, dims
,
2845 dstRowStride
, dstSlices
,
2846 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2847 srcAddr
, srcPacking
);
2851 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2854 srcWidth
, srcHeight
, srcDepth
,
2855 srcFormat
, srcType
, srcAddr
,
2857 ctx
->_ImageTransferState
);
2858 const GLfloat
*src
= tempImage
;
2859 GLint img
, row
, col
;
2862 for (img
= 0; img
< srcDepth
; img
++) {
2863 GLubyte
*dstRow
= dstSlices
[img
];
2864 for (row
= 0; row
< srcHeight
; row
++) {
2865 GLshort
*dst
= (GLshort
*) dstRow
;
2866 for (col
= 0; col
< srcWidth
; col
++) {
2869 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2870 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2876 dstRow
+= dstRowStride
;
2879 free((void *) tempImage
);
2885 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2888 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2890 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2892 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2893 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2897 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2900 srcWidth
, srcHeight
, srcDepth
,
2901 srcFormat
, srcType
, srcAddr
,
2903 ctx
->_ImageTransferState
);
2904 const GLfloat
*srcRow
= tempImage
;
2905 GLint img
, row
, col
;
2908 for (img
= 0; img
< srcDepth
; img
++) {
2909 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2910 for (row
= 0; row
< srcHeight
; row
++) {
2911 GLbyte
*dst
= dstRow
;
2912 for (col
= 0; col
< srcWidth
; col
++) {
2913 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2914 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2915 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2920 dstRow
+= dstRowStride
;
2923 free((void *) tempImage
);
2931 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2932 * MESA_FORMAT_SIGNED_RGBA8888_REV
2935 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2937 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2939 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2940 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2941 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2943 if (!ctx
->_ImageTransferState
&&
2944 baseInternalFormat
== GL_RGBA
&&
2945 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
2946 srcPacking
->SwapBytes
)) {
2947 /* simple memcpy path */
2948 memcpy_texture(ctx
, dims
,
2950 dstRowStride
, dstSlices
,
2951 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2952 srcAddr
, srcPacking
);
2956 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2959 srcWidth
, srcHeight
, srcDepth
,
2960 srcFormat
, srcType
, srcAddr
,
2962 ctx
->_ImageTransferState
);
2963 const GLfloat
*srcRow
= tempImage
;
2964 GLint img
, row
, col
;
2967 for (img
= 0; img
< srcDepth
; img
++) {
2968 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2969 for (row
= 0; row
< srcHeight
; row
++) {
2970 GLbyte
*dst
= dstRow
;
2971 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2972 for (col
= 0; col
< srcWidth
; col
++) {
2973 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2974 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2975 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2976 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2982 for (col
= 0; col
< srcWidth
; col
++) {
2983 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2984 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2985 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2986 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2991 dstRow
+= dstRowStride
;
2994 free((void *) tempImage
);
3001 * Store a combined depth/stencil texture image.
3004 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3006 const GLuint depthScale
= 0xffffff;
3007 const GLint srcRowStride
3008 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3011 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3012 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3013 srcFormat
== GL_DEPTH_COMPONENT
||
3014 srcFormat
== GL_STENCIL_INDEX
);
3015 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3017 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3018 ctx
->Pixel
.DepthBias
== 0.0f
&&
3019 !srcPacking
->SwapBytes
) {
3021 memcpy_texture(ctx
, dims
,
3023 dstRowStride
, dstSlices
,
3024 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3025 srcAddr
, srcPacking
);
3027 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3028 srcFormat
== GL_STENCIL_INDEX
) {
3029 /* In case we only upload depth we need to preserve the stencil */
3030 for (img
= 0; img
< srcDepth
; img
++) {
3031 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
3033 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3034 srcWidth
, srcHeight
,
3037 for (row
= 0; row
< srcHeight
; row
++) {
3038 GLuint depth
[MAX_WIDTH
];
3039 GLubyte stencil
[MAX_WIDTH
];
3041 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3043 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3044 keepstencil
= GL_TRUE
;
3046 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3047 keepdepth
= GL_TRUE
;
3050 if (keepdepth
== GL_FALSE
)
3051 /* the 24 depth bits will be in the low position: */
3052 _mesa_unpack_depth_span(ctx
, srcWidth
,
3053 GL_UNSIGNED_INT
, /* dst type */
3054 keepstencil
? depth
: dstRow
, /* dst addr */
3056 srcType
, src
, srcPacking
);
3058 if (keepstencil
== GL_FALSE
)
3059 /* get the 8-bit stencil values */
3060 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3061 GL_UNSIGNED_BYTE
, /* dst type */
3062 stencil
, /* dst addr */
3063 srcType
, src
, srcPacking
,
3064 ctx
->_ImageTransferState
);
3066 for (i
= 0; i
< srcWidth
; i
++) {
3068 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3070 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3073 src
+= srcRowStride
;
3074 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3083 * Store a combined depth/stencil texture image.
3086 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3088 const GLuint depthScale
= 0xffffff;
3089 const GLint srcRowStride
3090 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3093 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3094 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3095 srcFormat
== GL_DEPTH_COMPONENT
||
3096 srcFormat
== GL_STENCIL_INDEX
);
3097 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3098 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3100 for (img
= 0; img
< srcDepth
; img
++) {
3101 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
3103 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3104 srcWidth
, srcHeight
,
3107 for (row
= 0; row
< srcHeight
; row
++) {
3108 GLuint depth
[MAX_WIDTH
];
3109 GLubyte stencil
[MAX_WIDTH
];
3111 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3113 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3114 keepstencil
= GL_TRUE
;
3116 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3117 keepdepth
= GL_TRUE
;
3120 if (keepdepth
== GL_FALSE
)
3121 /* the 24 depth bits will be in the low position: */
3122 _mesa_unpack_depth_span(ctx
, srcWidth
,
3123 GL_UNSIGNED_INT
, /* dst type */
3124 keepstencil
? depth
: dstRow
, /* dst addr */
3126 srcType
, src
, srcPacking
);
3128 if (keepstencil
== GL_FALSE
)
3129 /* get the 8-bit stencil values */
3130 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3131 GL_UNSIGNED_BYTE
, /* dst type */
3132 stencil
, /* dst addr */
3133 srcType
, src
, srcPacking
,
3134 ctx
->_ImageTransferState
);
3136 /* merge stencil values into depth values */
3137 for (i
= 0; i
< srcWidth
; i
++) {
3139 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3141 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3144 src
+= srcRowStride
;
3145 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3153 * Store simple 8-bit/value stencil texture data.
3156 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3158 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3159 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3161 if (!ctx
->_ImageTransferState
&&
3162 !srcPacking
->SwapBytes
&&
3163 baseInternalFormat
== srcFormat
&&
3164 srcType
== GL_UNSIGNED_BYTE
) {
3165 /* simple memcpy path */
3166 memcpy_texture(ctx
, dims
,
3168 dstRowStride
, dstSlices
,
3169 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3170 srcAddr
, srcPacking
);
3173 const GLint srcRowStride
3174 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3177 for (img
= 0; img
< srcDepth
; img
++) {
3178 GLubyte
*dstRow
= dstSlices
[img
];
3180 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3181 srcWidth
, srcHeight
,
3184 for (row
= 0; row
< srcHeight
; row
++) {
3185 GLubyte stencil
[MAX_WIDTH
];
3188 /* get the 8-bit stencil values */
3189 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3190 GL_UNSIGNED_BYTE
, /* dst type */
3191 stencil
, /* dst addr */
3192 srcType
, src
, srcPacking
,
3193 ctx
->_ImageTransferState
);
3194 /* merge stencil values into depth values */
3195 for (i
= 0; i
< srcWidth
; i
++)
3196 dstRow
[i
] = stencil
[i
];
3198 src
+= srcRowStride
;
3199 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3210 * Store an image in any of the formats:
3211 * _mesa_texformat_rgba_float32
3212 * _mesa_texformat_rgb_float32
3213 * _mesa_texformat_alpha_float32
3214 * _mesa_texformat_luminance_float32
3215 * _mesa_texformat_luminance_alpha_float32
3216 * _mesa_texformat_intensity_float32
3219 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3221 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3222 const GLint components
= _mesa_components_in_format(baseFormat
);
3224 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3225 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3226 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3227 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3228 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3229 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3230 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3231 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3232 ASSERT(baseInternalFormat
== GL_RGBA
||
3233 baseInternalFormat
== GL_RGB
||
3234 baseInternalFormat
== GL_ALPHA
||
3235 baseInternalFormat
== GL_LUMINANCE
||
3236 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3237 baseInternalFormat
== GL_INTENSITY
||
3238 baseInternalFormat
== GL_RED
||
3239 baseInternalFormat
== GL_RG
);
3240 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
3242 if (!ctx
->_ImageTransferState
&&
3243 !srcPacking
->SwapBytes
&&
3244 baseInternalFormat
== srcFormat
&&
3245 baseInternalFormat
== baseFormat
&&
3246 srcType
== GL_FLOAT
) {
3247 /* simple memcpy path */
3248 memcpy_texture(ctx
, dims
,
3250 dstRowStride
, dstSlices
,
3251 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3252 srcAddr
, srcPacking
);
3256 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3259 srcWidth
, srcHeight
, srcDepth
,
3260 srcFormat
, srcType
, srcAddr
,
3262 ctx
->_ImageTransferState
);
3263 const GLfloat
*srcRow
= tempImage
;
3268 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3269 for (img
= 0; img
< srcDepth
; img
++) {
3270 GLubyte
*dstRow
= dstSlices
[img
];
3271 for (row
= 0; row
< srcHeight
; row
++) {
3272 memcpy(dstRow
, srcRow
, bytesPerRow
);
3273 dstRow
+= dstRowStride
;
3274 srcRow
+= srcWidth
* components
;
3278 free((void *) tempImage
);
3286 * As above, but store 16-bit floats.
3289 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3291 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3292 const GLint components
= _mesa_components_in_format(baseFormat
);
3294 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3295 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3296 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3297 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3298 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3299 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3300 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3301 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3302 ASSERT(baseInternalFormat
== GL_RGBA
||
3303 baseInternalFormat
== GL_RGB
||
3304 baseInternalFormat
== GL_ALPHA
||
3305 baseInternalFormat
== GL_LUMINANCE
||
3306 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3307 baseInternalFormat
== GL_INTENSITY
||
3308 baseInternalFormat
== GL_RED
||
3309 baseInternalFormat
== GL_RG
);
3310 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
3312 if (!ctx
->_ImageTransferState
&&
3313 !srcPacking
->SwapBytes
&&
3314 baseInternalFormat
== srcFormat
&&
3315 baseInternalFormat
== baseFormat
&&
3316 srcType
== GL_HALF_FLOAT_ARB
) {
3317 /* simple memcpy path */
3318 memcpy_texture(ctx
, dims
,
3320 dstRowStride
, dstSlices
,
3321 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3322 srcAddr
, srcPacking
);
3326 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3329 srcWidth
, srcHeight
, srcDepth
,
3330 srcFormat
, srcType
, srcAddr
,
3332 ctx
->_ImageTransferState
);
3333 const GLfloat
*src
= tempImage
;
3337 for (img
= 0; img
< srcDepth
; img
++) {
3338 GLubyte
*dstRow
= dstSlices
[img
];
3339 for (row
= 0; row
< srcHeight
; row
++) {
3340 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3342 for (i
= 0; i
< srcWidth
* components
; i
++) {
3343 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3345 dstRow
+= dstRowStride
;
3346 src
+= srcWidth
* components
;
3350 free((void *) tempImage
);
3356 /* non-normalized, signed int8 */
3358 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3360 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3361 const GLint components
= _mesa_components_in_format(baseFormat
);
3363 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3364 dstFormat
== MESA_FORMAT_RG_INT8
||
3365 dstFormat
== MESA_FORMAT_RGB_INT8
||
3366 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3367 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3368 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3369 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3370 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3371 ASSERT(baseInternalFormat
== GL_RGBA
||
3372 baseInternalFormat
== GL_RGB
||
3373 baseInternalFormat
== GL_RG
||
3374 baseInternalFormat
== GL_RED
||
3375 baseInternalFormat
== GL_ALPHA
||
3376 baseInternalFormat
== GL_LUMINANCE
||
3377 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3378 baseInternalFormat
== GL_INTENSITY
);
3379 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
3381 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3382 * to integer formats.
3384 if (!srcPacking
->SwapBytes
&&
3385 baseInternalFormat
== srcFormat
&&
3386 srcType
== GL_BYTE
) {
3387 /* simple memcpy path */
3388 memcpy_texture(ctx
, dims
,
3390 dstRowStride
, dstSlices
,
3391 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3392 srcAddr
, srcPacking
);
3396 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3399 srcWidth
, srcHeight
, srcDepth
,
3403 const GLuint
*src
= tempImage
;
3407 for (img
= 0; img
< srcDepth
; img
++) {
3408 GLubyte
*dstRow
= dstSlices
[img
];
3409 for (row
= 0; row
< srcHeight
; row
++) {
3410 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3412 for (i
= 0; i
< srcWidth
* components
; i
++) {
3413 dstTexel
[i
] = (GLbyte
) src
[i
];
3415 dstRow
+= dstRowStride
;
3416 src
+= srcWidth
* components
;
3420 free((void *) tempImage
);
3426 /* non-normalized, signed int16 */
3428 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3430 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3431 const GLint components
= _mesa_components_in_format(baseFormat
);
3433 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3434 dstFormat
== MESA_FORMAT_RG_INT16
||
3435 dstFormat
== MESA_FORMAT_RGB_INT16
||
3436 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3437 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3438 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3439 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3440 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3441 ASSERT(baseInternalFormat
== GL_RGBA
||
3442 baseInternalFormat
== GL_RGB
||
3443 baseInternalFormat
== GL_RG
||
3444 baseInternalFormat
== GL_RED
||
3445 baseInternalFormat
== GL_ALPHA
||
3446 baseInternalFormat
== GL_LUMINANCE
||
3447 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3448 baseInternalFormat
== GL_INTENSITY
);
3449 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
3451 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3452 * to integer formats.
3454 if (!srcPacking
->SwapBytes
&&
3455 baseInternalFormat
== srcFormat
&&
3456 srcType
== GL_SHORT
) {
3457 /* simple memcpy path */
3458 memcpy_texture(ctx
, dims
,
3460 dstRowStride
, dstSlices
,
3461 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3462 srcAddr
, srcPacking
);
3466 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3469 srcWidth
, srcHeight
, srcDepth
,
3473 const GLuint
*src
= tempImage
;
3477 for (img
= 0; img
< srcDepth
; img
++) {
3478 GLubyte
*dstRow
= dstSlices
[img
];
3479 for (row
= 0; row
< srcHeight
; row
++) {
3480 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3482 for (i
= 0; i
< srcWidth
* components
; i
++) {
3483 dstTexel
[i
] = (GLint
) src
[i
];
3485 dstRow
+= dstRowStride
;
3486 src
+= srcWidth
* components
;
3490 free((void *) tempImage
);
3496 /* non-normalized, signed int32 */
3498 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3500 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3501 const GLint components
= _mesa_components_in_format(baseFormat
);
3503 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3504 dstFormat
== MESA_FORMAT_RG_INT32
||
3505 dstFormat
== MESA_FORMAT_RGB_INT32
||
3506 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3507 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3508 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3509 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3510 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3511 ASSERT(baseInternalFormat
== GL_RGBA
||
3512 baseInternalFormat
== GL_RGB
||
3513 baseInternalFormat
== GL_RG
||
3514 baseInternalFormat
== GL_RED
||
3515 baseInternalFormat
== GL_ALPHA
||
3516 baseInternalFormat
== GL_LUMINANCE
||
3517 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3518 baseInternalFormat
== GL_INTENSITY
);
3519 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
3521 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3522 * to integer formats.
3524 if (!srcPacking
->SwapBytes
&&
3525 baseInternalFormat
== srcFormat
&&
3526 srcType
== GL_INT
) {
3527 /* simple memcpy path */
3528 memcpy_texture(ctx
, dims
,
3530 dstRowStride
, dstSlices
,
3531 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3532 srcAddr
, srcPacking
);
3536 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3539 srcWidth
, srcHeight
, srcDepth
,
3543 const GLuint
*src
= tempImage
;
3547 for (img
= 0; img
< srcDepth
; img
++) {
3548 GLubyte
*dstRow
= dstSlices
[img
];
3549 for (row
= 0; row
< srcHeight
; row
++) {
3550 GLint
*dstTexel
= (GLint
*) dstRow
;
3552 for (i
= 0; i
< srcWidth
* components
; i
++) {
3553 dstTexel
[i
] = (GLint
) src
[i
];
3555 dstRow
+= dstRowStride
;
3556 src
+= srcWidth
* components
;
3560 free((void *) tempImage
);
3566 /* non-normalized, unsigned int8 */
3568 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3570 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3571 const GLint components
= _mesa_components_in_format(baseFormat
);
3573 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3574 dstFormat
== MESA_FORMAT_RG_UINT8
||
3575 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3576 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3577 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3578 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3579 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3580 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3581 ASSERT(baseInternalFormat
== GL_RGBA
||
3582 baseInternalFormat
== GL_RGB
||
3583 baseInternalFormat
== GL_RG
||
3584 baseInternalFormat
== GL_RED
||
3585 baseInternalFormat
== GL_ALPHA
||
3586 baseInternalFormat
== GL_LUMINANCE
||
3587 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3588 baseInternalFormat
== GL_INTENSITY
);
3589 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3591 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3592 * to integer formats.
3594 if (!srcPacking
->SwapBytes
&&
3595 baseInternalFormat
== srcFormat
&&
3596 srcType
== GL_UNSIGNED_BYTE
) {
3597 /* simple memcpy path */
3598 memcpy_texture(ctx
, dims
,
3600 dstRowStride
, dstSlices
,
3601 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3602 srcAddr
, srcPacking
);
3606 const GLuint
*tempImage
=
3607 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3608 srcWidth
, srcHeight
, srcDepth
,
3609 srcFormat
, srcType
, srcAddr
, srcPacking
);
3610 const GLuint
*src
= tempImage
;
3614 for (img
= 0; img
< srcDepth
; img
++) {
3615 GLubyte
*dstRow
= dstSlices
[img
];
3616 for (row
= 0; row
< srcHeight
; row
++) {
3617 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3619 for (i
= 0; i
< srcWidth
* components
; i
++) {
3620 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3622 dstRow
+= dstRowStride
;
3623 src
+= srcWidth
* components
;
3627 free((void *) tempImage
);
3633 /* non-normalized, unsigned int16 */
3635 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3637 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3638 const GLint components
= _mesa_components_in_format(baseFormat
);
3640 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3641 dstFormat
== MESA_FORMAT_RG_UINT16
||
3642 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3643 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3644 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3645 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3646 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3647 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3648 ASSERT(baseInternalFormat
== GL_RGBA
||
3649 baseInternalFormat
== GL_RGB
||
3650 baseInternalFormat
== GL_RG
||
3651 baseInternalFormat
== GL_RED
||
3652 baseInternalFormat
== GL_ALPHA
||
3653 baseInternalFormat
== GL_LUMINANCE
||
3654 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3655 baseInternalFormat
== GL_INTENSITY
);
3656 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3658 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3659 * to integer formats.
3661 if (!srcPacking
->SwapBytes
&&
3662 baseInternalFormat
== srcFormat
&&
3663 srcType
== GL_UNSIGNED_SHORT
) {
3664 /* simple memcpy path */
3665 memcpy_texture(ctx
, dims
,
3667 dstRowStride
, dstSlices
,
3668 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3669 srcAddr
, srcPacking
);
3673 const GLuint
*tempImage
=
3674 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3675 srcWidth
, srcHeight
, srcDepth
,
3676 srcFormat
, srcType
, srcAddr
, srcPacking
);
3677 const GLuint
*src
= tempImage
;
3681 for (img
= 0; img
< srcDepth
; img
++) {
3682 GLubyte
*dstRow
= dstSlices
[img
];
3683 for (row
= 0; row
< srcHeight
; row
++) {
3684 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3686 for (i
= 0; i
< srcWidth
* components
; i
++) {
3687 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3689 dstRow
+= dstRowStride
;
3690 src
+= srcWidth
* components
;
3694 free((void *) tempImage
);
3700 /* non-normalized, unsigned int32 */
3702 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3704 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3705 const GLint components
= _mesa_components_in_format(baseFormat
);
3707 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3708 dstFormat
== MESA_FORMAT_RG_UINT32
||
3709 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3710 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3711 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3712 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3713 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3714 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3715 ASSERT(baseInternalFormat
== GL_RGBA
||
3716 baseInternalFormat
== GL_RGB
||
3717 baseInternalFormat
== GL_RG
||
3718 baseInternalFormat
== GL_RED
||
3719 baseInternalFormat
== GL_ALPHA
||
3720 baseInternalFormat
== GL_LUMINANCE
||
3721 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3722 baseInternalFormat
== GL_INTENSITY
);
3723 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3725 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3726 * to integer formats.
3728 if (!srcPacking
->SwapBytes
&&
3729 baseInternalFormat
== srcFormat
&&
3730 srcType
== GL_UNSIGNED_INT
) {
3731 /* simple memcpy path */
3732 memcpy_texture(ctx
, dims
,
3734 dstRowStride
, dstSlices
,
3735 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3736 srcAddr
, srcPacking
);
3740 const GLuint
*tempImage
=
3741 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3742 srcWidth
, srcHeight
, srcDepth
,
3743 srcFormat
, srcType
, srcAddr
, srcPacking
);
3744 const GLuint
*src
= tempImage
;
3748 for (img
= 0; img
< srcDepth
; img
++) {
3749 GLubyte
*dstRow
= dstSlices
[img
];
3750 for (row
= 0; row
< srcHeight
; row
++) {
3751 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3753 for (i
= 0; i
< srcWidth
* components
; i
++) {
3754 dstTexel
[i
] = src
[i
];
3756 dstRow
+= dstRowStride
;
3757 src
+= srcWidth
* components
;
3761 free((void *) tempImage
);
3769 #if FEATURE_EXT_texture_sRGB
3771 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3773 gl_format newDstFormat
;
3776 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3778 /* reuse normal rgb texstore code */
3779 newDstFormat
= MESA_FORMAT_RGB888
;
3781 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3783 dstRowStride
, dstSlices
,
3784 srcWidth
, srcHeight
, srcDepth
,
3786 srcAddr
, srcPacking
);
3792 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3794 gl_format newDstFormat
;
3797 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3799 /* reuse normal rgba texstore code */
3800 newDstFormat
= MESA_FORMAT_RGBA8888
;
3801 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3803 dstRowStride
, dstSlices
,
3804 srcWidth
, srcHeight
, srcDepth
,
3806 srcAddr
, srcPacking
);
3812 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3814 gl_format newDstFormat
;
3817 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3819 /* reuse normal rgba texstore code */
3820 newDstFormat
= MESA_FORMAT_ARGB8888
;
3822 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3824 dstRowStride
, dstSlices
,
3825 srcWidth
, srcHeight
, srcDepth
,
3827 srcAddr
, srcPacking
);
3833 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3835 gl_format newDstFormat
;
3838 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3840 newDstFormat
= MESA_FORMAT_L8
;
3842 /* _mesa_textore_a8 handles luminance8 too */
3843 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3845 dstRowStride
, dstSlices
,
3846 srcWidth
, srcHeight
, srcDepth
,
3848 srcAddr
, srcPacking
);
3854 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3856 gl_format newDstFormat
;
3859 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3861 /* reuse normal luminance/alpha texstore code */
3862 newDstFormat
= MESA_FORMAT_AL88
;
3864 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3866 dstRowStride
, dstSlices
,
3867 srcWidth
, srcHeight
, srcDepth
,
3869 srcAddr
, srcPacking
);
3875 /* these are used only in texstore_funcs[] below */
3876 #define _mesa_texstore_srgb8 NULL
3877 #define _mesa_texstore_srgba8 NULL
3878 #define _mesa_texstore_sargb8 NULL
3879 #define _mesa_texstore_sl8 NULL
3880 #define _mesa_texstore_sla8 NULL
3882 #endif /* FEATURE_EXT_texture_sRGB */
3885 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3887 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3889 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
3890 ASSERT(baseInternalFormat
== GL_RGB
);
3892 if (!ctx
->_ImageTransferState
&&
3893 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3894 srcPacking
->SwapBytes
)) {
3895 /* simple memcpy path */
3896 memcpy_texture(ctx
, dims
,
3898 dstRowStride
, dstSlices
,
3899 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3900 srcAddr
, srcPacking
);
3904 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3907 srcWidth
, srcHeight
, srcDepth
,
3908 srcFormat
, srcType
, srcAddr
,
3910 ctx
->_ImageTransferState
);
3911 const GLfloat
*srcRow
= tempImage
;
3912 GLint img
, row
, col
;
3915 for (img
= 0; img
< srcDepth
; img
++) {
3916 GLubyte
*dstRow
= dstSlices
[img
];
3917 for (row
= 0; row
< srcHeight
; row
++) {
3918 GLuint
*dstUI
= (GLuint
*)dstRow
;
3919 for (col
= 0; col
< srcWidth
; col
++) {
3920 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3922 dstRow
+= dstRowStride
;
3923 srcRow
+= srcWidth
* 3;
3927 free((void *) tempImage
);
3933 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
3935 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3937 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
3938 ASSERT(baseInternalFormat
== GL_RGB
);
3940 if (!ctx
->_ImageTransferState
&&
3941 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3942 srcPacking
->SwapBytes
)) {
3943 /* simple memcpy path */
3944 memcpy_texture(ctx
, dims
,
3946 dstRowStride
, dstSlices
,
3947 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3948 srcAddr
, srcPacking
);
3952 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3955 srcWidth
, srcHeight
, srcDepth
,
3956 srcFormat
, srcType
, srcAddr
,
3958 ctx
->_ImageTransferState
);
3959 const GLfloat
*srcRow
= tempImage
;
3960 GLint img
, row
, col
;
3963 for (img
= 0; img
< srcDepth
; img
++) {
3964 GLubyte
*dstRow
= dstSlices
[img
];
3965 for (row
= 0; row
< srcHeight
; row
++) {
3966 GLuint
*dstUI
= (GLuint
*)dstRow
;
3967 for (col
= 0; col
< srcWidth
; col
++) {
3968 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
3970 dstRow
+= dstRowStride
;
3971 srcRow
+= srcWidth
* 3;
3975 free((void *) tempImage
);
3982 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
3984 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
3985 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
3986 srcFormat
== GL_DEPTH_COMPONENT
||
3987 srcFormat
== GL_STENCIL_INDEX
);
3988 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
3989 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
3991 if (srcFormat
== GL_DEPTH_STENCIL
&&
3992 ctx
->Pixel
.DepthScale
== 1.0f
&&
3993 ctx
->Pixel
.DepthBias
== 0.0f
&&
3994 !srcPacking
->SwapBytes
) {
3996 memcpy_texture(ctx
, dims
,
3998 dstRowStride
, dstSlices
,
3999 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4000 srcAddr
, srcPacking
);
4002 else if (srcFormat
== GL_DEPTH_COMPONENT
||
4003 srcFormat
== GL_STENCIL_INDEX
) {
4005 const GLint srcRowStride
4006 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
4009 /* In case we only upload depth we need to preserve the stencil */
4010 for (img
= 0; img
< srcDepth
; img
++) {
4011 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
4013 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
4014 srcWidth
, srcHeight
,
4017 for (row
= 0; row
< srcHeight
; row
++) {
4018 /* The unpack functions with:
4019 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4020 * only write their own dword, so the other dword (stencil
4021 * or depth) is preserved. */
4022 if (srcFormat
!= GL_STENCIL_INDEX
)
4023 _mesa_unpack_depth_span(ctx
, srcWidth
,
4024 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4025 dstRow
, /* dst addr */
4026 ~0U, srcType
, src
, srcPacking
);
4028 if (srcFormat
!= GL_DEPTH_COMPONENT
)
4029 _mesa_unpack_stencil_span(ctx
, srcWidth
,
4030 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4031 dstRow
, /* dst addr */
4032 srcType
, src
, srcPacking
,
4033 ctx
->_ImageTransferState
);
4035 src
+= srcRowStride
;
4036 dstRow
+= dstRowStride
/ sizeof(uint64_t);
4044 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
4046 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4048 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
4049 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
4051 if (baseInternalFormat
== GL_RGBA
&&
4052 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
4053 srcPacking
->SwapBytes
)) {
4054 /* simple memcpy path */
4055 memcpy_texture(ctx
, dims
,
4057 dstRowStride
, dstSlices
,
4058 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4059 srcAddr
, srcPacking
);
4063 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
4066 srcWidth
, srcHeight
,
4067 srcDepth
, srcFormat
,
4070 const GLuint
*src
= tempImage
;
4071 GLint img
, row
, col
;
4074 for (img
= 0; img
< srcDepth
; img
++) {
4075 GLubyte
*dstRow
= dstSlices
[img
];
4077 for (row
= 0; row
< srcHeight
; row
++) {
4078 GLuint
*dstUI
= (GLuint
*) dstRow
;
4079 for (col
= 0; col
< srcWidth
; col
++) {
4085 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
4088 dstRow
+= dstRowStride
;
4091 free((void *) tempImage
);
4097 _mesa_texstore_null(TEXSTORE_PARAMS
)
4099 (void) ctx
; (void) dims
;
4100 (void) baseInternalFormat
;
4102 (void) dstRowStride
; (void) dstSlices
,
4103 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4104 (void) srcFormat
; (void) srcType
;
4108 /* should never happen */
4109 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4115 * Return the StoreTexImageFunc pointer to store an image in the given format.
4117 static StoreTexImageFunc
4118 _mesa_get_texstore_func(gl_format format
)
4120 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
4121 static GLboolean initialized
= GL_FALSE
;
4124 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
4126 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
4127 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
4128 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
4129 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
4130 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
4131 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
4132 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
4133 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
4134 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
4135 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
4136 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
4137 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
4138 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
4139 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
4140 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
4141 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
4142 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
4143 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
4144 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
4145 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
4146 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
4147 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
4148 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
4149 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
4150 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
4151 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
4152 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
4153 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
4154 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
4155 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
4156 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
4157 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
4158 table
[MESA_FORMAT_GR88
] = _mesa_texstore_unorm88
;
4159 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
4160 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
4161 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
4162 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
4163 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
4164 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
4165 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
4166 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
4167 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
4168 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
4169 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
4170 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
4171 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
4172 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
4173 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
4174 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
4175 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
4176 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4177 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4178 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4179 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4180 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
4181 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
4182 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4183 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4184 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4185 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4186 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4187 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4188 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
4189 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
4190 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4191 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4192 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
4193 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
4194 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4195 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4196 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
4197 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
4198 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
4199 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
4200 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
4201 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
4202 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
4203 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
4204 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
4205 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
4206 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
4207 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
4208 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
4209 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
4210 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
4211 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
4212 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
4213 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
4214 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
4215 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
4216 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
4217 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
4218 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
4219 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
4220 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
4221 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
4222 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
4223 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
4224 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
4225 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
4226 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
4227 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
4228 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
4229 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
4230 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
4231 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
4232 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
4233 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
4235 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4236 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4237 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4238 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4239 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4240 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4242 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
4243 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
4244 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
4245 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
4246 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
4247 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
4249 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
4250 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
4251 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
4252 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
4253 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
4254 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4256 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4257 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4258 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4259 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4260 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4261 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4263 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4264 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4265 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4266 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4267 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4268 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4269 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4270 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4271 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4272 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4273 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4274 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4276 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4277 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4278 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4279 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4280 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4281 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4282 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4283 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4284 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4285 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4286 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4287 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4289 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
4290 initialized
= GL_TRUE
;
4293 ASSERT(table
[format
]);
4294 return table
[format
];
4299 * Store user data into texture memory.
4300 * Called via glTex[Sub]Image1/2/3D()
4303 _mesa_texstore(TEXSTORE_PARAMS
)
4305 StoreTexImageFunc storeImage
;
4308 storeImage
= _mesa_get_texstore_func(dstFormat
);
4310 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4312 dstRowStride
, dstSlices
,
4313 srcWidth
, srcHeight
, srcDepth
,
4314 srcFormat
, srcType
, srcAddr
, srcPacking
);
4320 * Normally, we'll only _write_ texel data to a texture when we map it.
4321 * But if the user is providing depth or stencil values and the texture
4322 * image is a combined depth/stencil format, we'll actually read from
4323 * the texture buffer too (in order to insert the depth or stencil values.
4324 * \param userFormat the user-provided image format
4325 * \param texFormat the destination texture format
4328 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4330 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4331 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4332 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4334 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
4339 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
4341 * The source of the image data may be user memory or a PBO. In the later
4342 * case, we'll map the PBO, copy from it, then unmap it.
4345 store_texsubimage(struct gl_context
*ctx
,
4346 struct gl_texture_image
*texImage
,
4347 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4348 GLint width
, GLint height
, GLint depth
,
4349 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4350 const struct gl_pixelstore_attrib
*packing
,
4354 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4355 const GLenum target
= texImage
->TexObject
->Target
;
4356 GLboolean success
= GL_FALSE
;
4357 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
4358 GLint srcImageStride
= 0;
4361 assert(xoffset
+ width
<= texImage
->Width
);
4362 assert(yoffset
+ height
<= texImage
->Height
);
4363 assert(zoffset
+ depth
<= texImage
->Depth
);
4369 case GL_TEXTURE_2D_ARRAY
:
4377 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4378 src
= (const GLubyte
*)
4379 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
4380 format
, type
, pixels
, packing
, caller
);
4384 /* compute slice info (and do some sanity checks) */
4387 case GL_TEXTURE_RECTANGLE
:
4388 case GL_TEXTURE_CUBE_MAP
:
4389 /* one image slice, nothing special needs to be done */
4392 assert(height
== 1);
4394 assert(yoffset
== 0);
4395 assert(zoffset
== 0);
4397 case GL_TEXTURE_1D_ARRAY
:
4399 assert(zoffset
== 0);
4401 sliceOffset
= yoffset
;
4404 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
4406 case GL_TEXTURE_2D_ARRAY
:
4408 sliceOffset
= zoffset
;
4411 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4415 /* we'll store 3D images as a series of slices */
4417 sliceOffset
= zoffset
;
4418 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4422 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4426 assert(numSlices
== 1 || srcImageStride
!= 0);
4428 for (slice
= 0; slice
< numSlices
; slice
++) {
4432 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4433 slice
+ sliceOffset
,
4434 xoffset
, yoffset
, width
, height
,
4435 mapMode
, &dstMap
, &dstRowStride
);
4437 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4438 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4439 * used for 3D images.
4441 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4442 texImage
->TexFormat
,
4445 width
, height
, 1, /* w, h, d */
4446 format
, type
, src
, packing
);
4448 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4451 src
+= srcImageStride
;
4458 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4460 _mesa_unmap_teximage_pbo(ctx
, packing
);
4466 * This is the fallback for Driver.TexImage1D().
4469 _mesa_store_teximage1d(struct gl_context
*ctx
,
4470 struct gl_texture_image
*texImage
,
4471 GLint internalFormat
,
4472 GLint width
, GLint border
,
4473 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4474 const struct gl_pixelstore_attrib
*packing
)
4479 /* allocate storage for texture data */
4480 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4482 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4486 store_texsubimage(ctx
, texImage
,
4487 0, 0, 0, width
, 1, 1,
4488 format
, type
, pixels
, packing
, "glTexImage1D");
4493 * This is the fallback for Driver.TexImage2D().
4496 _mesa_store_teximage2d(struct gl_context
*ctx
,
4497 struct gl_texture_image
*texImage
,
4498 GLint internalFormat
,
4499 GLint width
, GLint height
, GLint border
,
4500 GLenum format
, GLenum type
, const void *pixels
,
4501 const struct gl_pixelstore_attrib
*packing
)
4503 if (width
== 0 || height
== 0)
4506 /* allocate storage for texture data */
4507 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4508 width
, height
, 1)) {
4509 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4513 store_texsubimage(ctx
, texImage
,
4514 0, 0, 0, width
, height
, 1,
4515 format
, type
, pixels
, packing
, "glTexImage2D");
4521 * This is the fallback for Driver.TexImage3D().
4524 _mesa_store_teximage3d(struct gl_context
*ctx
,
4525 struct gl_texture_image
*texImage
,
4526 GLint internalFormat
,
4527 GLint width
, GLint height
, GLint depth
, GLint border
,
4528 GLenum format
, GLenum type
, const void *pixels
,
4529 const struct gl_pixelstore_attrib
*packing
)
4531 if (width
== 0 || height
== 0 || depth
== 0)
4534 /* allocate storage for texture data */
4535 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4536 width
, height
, depth
)) {
4537 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4541 store_texsubimage(ctx
, texImage
,
4542 0, 0, 0, width
, height
, depth
,
4543 format
, type
, pixels
, packing
, "glTexImage3D");
4550 * This is the fallback for Driver.TexSubImage1D().
4553 _mesa_store_texsubimage1d(struct gl_context
*ctx
,
4554 struct gl_texture_image
*texImage
,
4555 GLint xoffset
, GLint width
,
4556 GLenum format
, GLenum type
, const void *pixels
,
4557 const struct gl_pixelstore_attrib
*packing
)
4559 store_texsubimage(ctx
, texImage
,
4560 xoffset
, 0, 0, width
, 1, 1,
4561 format
, type
, pixels
, packing
, "glTexSubImage1D");
4567 * This is the fallback for Driver.TexSubImage2D().
4570 _mesa_store_texsubimage2d(struct gl_context
*ctx
,
4571 struct gl_texture_image
*texImage
,
4572 GLint xoffset
, GLint yoffset
,
4573 GLint width
, GLint height
,
4574 GLenum format
, GLenum type
, const void *pixels
,
4575 const struct gl_pixelstore_attrib
*packing
)
4577 store_texsubimage(ctx
, texImage
,
4578 xoffset
, yoffset
, 0, width
, height
, 1,
4579 format
, type
, pixels
, packing
, "glTexSubImage2D");
4584 * This is the fallback for Driver.TexSubImage3D().
4587 _mesa_store_texsubimage3d(struct gl_context
*ctx
,
4588 struct gl_texture_image
*texImage
,
4589 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4590 GLint width
, GLint height
, GLint depth
,
4591 GLenum format
, GLenum type
, const void *pixels
,
4592 const struct gl_pixelstore_attrib
*packing
)
4594 store_texsubimage(ctx
, texImage
,
4595 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4596 format
, type
, pixels
, packing
, "glTexSubImage3D");
4601 * Fallback for Driver.CompressedTexImage1D()
4604 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4605 struct gl_texture_image
*texImage
,
4606 GLint internalFormat
,
4607 GLint width
, GLint border
,
4608 GLsizei imageSize
, const GLvoid
*data
)
4610 /* no compressed 1D image formats at this time */
4612 (void) internalFormat
;
4613 (void) width
; (void) border
;
4614 (void) imageSize
; (void) data
;
4621 * Fallback for Driver.CompressedTexImage2D()
4624 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4625 struct gl_texture_image
*texImage
,
4626 GLint internalFormat
,
4627 GLint width
, GLint height
, GLint border
,
4628 GLsizei imageSize
, const GLvoid
*data
)
4630 /* This is pretty simple, because unlike the general texstore path we don't
4631 * have to worry about the usual image unpacking or image transfer
4635 ASSERT(texImage
->Width
> 0);
4636 ASSERT(texImage
->Height
> 0);
4637 ASSERT(texImage
->Depth
== 1);
4639 /* allocate storage for texture data */
4640 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4641 width
, height
, 1)) {
4642 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4646 _mesa_store_compressed_texsubimage2d(ctx
, texImage
,
4649 texImage
->TexFormat
,
4656 * Fallback for Driver.CompressedTexImage3D()
4659 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4660 struct gl_texture_image
*texImage
,
4661 GLint internalFormat
,
4662 GLint width
, GLint height
, GLint depth
,
4664 GLsizei imageSize
, const GLvoid
*data
)
4666 /* this space intentionally left blank */
4668 (void) internalFormat
;
4669 (void) width
; (void) height
; (void) depth
;
4671 (void) imageSize
; (void) data
;
4678 * Fallback for Driver.CompressedTexSubImage1D()
4681 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
,
4682 struct gl_texture_image
*texImage
,
4683 GLint xoffset
, GLsizei width
,
4685 GLsizei imageSize
, const GLvoid
*data
)
4687 /* there are no compressed 1D texture formats yet */
4689 (void) xoffset
; (void) width
;
4691 (void) imageSize
; (void) data
;
4697 * Fallback for Driver.CompressedTexSubImage2D()
4700 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
,
4701 struct gl_texture_image
*texImage
,
4702 GLint xoffset
, GLint yoffset
,
4703 GLsizei width
, GLsizei height
,
4705 GLsizei imageSize
, const GLvoid
*data
)
4707 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
4711 const gl_format texFormat
= texImage
->TexFormat
;
4714 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4716 /* these should have been caught sooner */
4717 ASSERT((width
% bw
) == 0 || width
< bw
);
4718 ASSERT((height
% bh
) == 0 || height
< bh
);
4719 ASSERT((xoffset
% bw
) == 0);
4720 ASSERT((yoffset
% bh
) == 0);
4722 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4723 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4725 "glCompressedTexSubImage2D");
4729 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4730 src
= (const GLubyte
*) data
;
4732 /* Map dest texture buffer */
4733 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4734 xoffset
, yoffset
, width
, height
,
4735 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4736 &dstMap
, &dstRowStride
);
4739 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4740 rows
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4742 /* copy rows of blocks */
4743 for (i
= 0; i
< rows
; i
++) {
4744 memcpy(dstMap
, src
, bytesPerRow
);
4745 dstMap
+= dstRowStride
;
4746 src
+= srcRowStride
;
4749 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4752 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage2D");
4755 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4760 * Fallback for Driver.CompressedTexSubImage3D()
4763 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
,
4764 struct gl_texture_image
*texImage
,
4765 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4766 GLsizei width
, GLsizei height
, GLsizei depth
,
4768 GLsizei imageSize
, const GLvoid
*data
)
4770 /* there are no compressed 3D texture formats yet */
4772 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4773 (void) width
; (void) height
; (void) depth
;
4775 (void) imageSize
; (void) data
;