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"
67 #include "texcompress.h"
68 #include "texcompress_fxt1.h"
69 #include "texcompress_rgtc.h"
70 #include "texcompress_s3tc.h"
83 * Texture image storage function.
85 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
89 * Return GL_TRUE if the given image format is one that be converted
90 * to another format by swizzling.
93 can_swizzle(GLenum logicalBaseFormat
)
95 switch (logicalBaseFormat
) {
98 case GL_LUMINANCE_ALPHA
:
134 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
135 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
136 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
137 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
140 static const struct {
143 GLubyte from_rgba
[6];
144 } mappings
[MAX_IDX
] =
154 MAP4(ZERO
, ZERO
, ZERO
, 0),
184 MAP4(0, ZERO
, ZERO
, ONE
),
190 MAP4(ZERO
, 0, ZERO
, ONE
),
196 MAP4(ZERO
, ZERO
, 0, ONE
),
220 MAP4(0, 1, ZERO
, ONE
),
228 * Convert a GL image format enum to an IDX_* value (see above).
231 get_map_idx(GLenum value
)
234 case GL_LUMINANCE
: return IDX_LUMINANCE
;
235 case GL_ALPHA
: return IDX_ALPHA
;
236 case GL_INTENSITY
: return IDX_INTENSITY
;
237 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
238 case GL_RGB
: return IDX_RGB
;
239 case GL_RGBA
: return IDX_RGBA
;
240 case GL_RED
: return IDX_RED
;
241 case GL_GREEN
: return IDX_GREEN
;
242 case GL_BLUE
: return IDX_BLUE
;
243 case GL_BGR
: return IDX_BGR
;
244 case GL_BGRA
: return IDX_BGRA
;
245 case GL_ABGR_EXT
: return IDX_ABGR
;
246 case GL_RG
: return IDX_RG
;
248 _mesa_problem(NULL
, "Unexpected inFormat");
255 * When promoting texture formats (see below) we need to compute the
256 * mapping of dest components back to source components.
257 * This function does that.
258 * \param inFormat the incoming format of the texture
259 * \param outFormat the final texture format
260 * \return map[6] a full 6-component map
263 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
266 const int inFmt
= get_map_idx(inFormat
);
267 const int outFmt
= get_map_idx(outFormat
);
268 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
269 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
272 for (i
= 0; i
< 4; i
++)
273 map
[i
] = in2rgba
[rgba2out
[i
]];
279 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
280 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
281 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
293 * Make a temporary (color) texture image with GLfloat components.
294 * Apply all needed pixel unpacking and pixel transfer operations.
295 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
296 * Suppose the user specifies GL_LUMINANCE as the internal texture format
297 * but the graphics hardware doesn't support luminance textures. So, we might
298 * use an RGB hardware format instead.
299 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
301 * \param ctx the rendering context
302 * \param dims image dimensions: 1, 2 or 3
303 * \param logicalBaseFormat basic texture derived from the user's
304 * internal texture format value
305 * \param textureBaseFormat the actual basic format of the texture
306 * \param srcWidth source image width
307 * \param srcHeight source image height
308 * \param srcDepth source image depth
309 * \param srcFormat source image format
310 * \param srcType source image type
311 * \param srcAddr source image address
312 * \param srcPacking source image pixel packing
313 * \return resulting image with format = textureBaseFormat and type = GLfloat.
316 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
317 GLenum logicalBaseFormat
,
318 GLenum textureBaseFormat
,
319 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
320 GLenum srcFormat
, GLenum srcType
,
321 const GLvoid
*srcAddr
,
322 const struct gl_pixelstore_attrib
*srcPacking
,
323 GLbitfield transferOps
)
326 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
327 const GLint srcStride
=
328 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
332 ASSERT(dims
>= 1 && dims
<= 3);
334 ASSERT(logicalBaseFormat
== GL_RGBA
||
335 logicalBaseFormat
== GL_RGB
||
336 logicalBaseFormat
== GL_RG
||
337 logicalBaseFormat
== GL_RED
||
338 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
339 logicalBaseFormat
== GL_LUMINANCE
||
340 logicalBaseFormat
== GL_ALPHA
||
341 logicalBaseFormat
== GL_INTENSITY
||
342 logicalBaseFormat
== GL_COLOR_INDEX
||
343 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
345 ASSERT(textureBaseFormat
== GL_RGBA
||
346 textureBaseFormat
== GL_RGB
||
347 textureBaseFormat
== GL_RG
||
348 textureBaseFormat
== GL_RED
||
349 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
350 textureBaseFormat
== GL_LUMINANCE
||
351 textureBaseFormat
== GL_ALPHA
||
352 textureBaseFormat
== GL_INTENSITY
||
353 textureBaseFormat
== GL_COLOR_INDEX
||
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_ALPHA
);
464 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
465 * components
* sizeof(GLuint
));
470 for (img
= 0; img
< srcDepth
; img
++) {
472 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
476 for (row
= 0; row
< srcHeight
; row
++) {
477 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
478 dst
, srcFormat
, srcType
, src
,
480 dst
+= srcWidth
* components
;
485 if (logicalBaseFormat
!= textureBaseFormat
) {
487 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
488 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
493 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
494 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
495 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
497 /* The actual texture format should have at least as many components
498 * as the logical texture format.
500 ASSERT(texComponents
>= logComponents
);
502 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
503 * texComponents
* sizeof(GLuint
));
509 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
511 n
= srcWidth
* srcHeight
* srcDepth
;
512 for (i
= 0; i
< n
; i
++) {
514 for (k
= 0; k
< texComponents
; k
++) {
517 newImage
[i
* texComponents
+ k
] = 0.0F
;
519 newImage
[i
* texComponents
+ k
] = 1.0F
;
521 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
526 tempImage
= newImage
;
535 * Make a temporary (color) texture image with GLchan components.
536 * Apply all needed pixel unpacking and pixel transfer operations.
537 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
538 * Suppose the user specifies GL_LUMINANCE as the internal texture format
539 * but the graphics hardware doesn't support luminance textures. So, we might
540 * use an RGB hardware format instead.
541 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
543 * \param ctx the rendering context
544 * \param dims image dimensions: 1, 2 or 3
545 * \param logicalBaseFormat basic texture derived from the user's
546 * internal texture format value
547 * \param textureBaseFormat the actual basic format of the texture
548 * \param srcWidth source image width
549 * \param srcHeight source image height
550 * \param srcDepth source image depth
551 * \param srcFormat source image format
552 * \param srcType source image type
553 * \param srcAddr source image address
554 * \param srcPacking source image pixel packing
555 * \return resulting image with format = textureBaseFormat and type = GLchan.
558 _mesa_make_temp_chan_image(struct gl_context
*ctx
, GLuint dims
,
559 GLenum logicalBaseFormat
,
560 GLenum textureBaseFormat
,
561 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
562 GLenum srcFormat
, GLenum srcType
,
563 const GLvoid
*srcAddr
,
564 const struct gl_pixelstore_attrib
*srcPacking
)
566 GLuint transferOps
= ctx
->_ImageTransferState
;
567 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
569 GLchan
*tempImage
, *dst
;
571 ASSERT(dims
>= 1 && dims
<= 3);
573 ASSERT(logicalBaseFormat
== GL_RGBA
||
574 logicalBaseFormat
== GL_RGB
||
575 logicalBaseFormat
== GL_RG
||
576 logicalBaseFormat
== GL_RED
||
577 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
578 logicalBaseFormat
== GL_LUMINANCE
||
579 logicalBaseFormat
== GL_ALPHA
||
580 logicalBaseFormat
== GL_INTENSITY
);
582 ASSERT(textureBaseFormat
== GL_RGBA
||
583 textureBaseFormat
== GL_RGB
||
584 textureBaseFormat
== GL_RG
||
585 textureBaseFormat
== GL_RED
||
586 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
587 textureBaseFormat
== GL_LUMINANCE
||
588 textureBaseFormat
== GL_ALPHA
||
589 textureBaseFormat
== GL_INTENSITY
);
591 /* unpack and transfer the source image */
592 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
593 * components
* sizeof(GLchan
));
599 for (img
= 0; img
< srcDepth
; img
++) {
600 const GLint srcStride
=
601 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
603 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
607 for (row
= 0; row
< srcHeight
; row
++) {
608 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
609 srcFormat
, srcType
, src
, srcPacking
,
611 dst
+= srcWidth
* components
;
616 if (logicalBaseFormat
!= textureBaseFormat
) {
617 /* one more conversion step */
618 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
619 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
624 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
625 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
626 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
628 /* The actual texture format should have at least as many components
629 * as the logical texture format.
631 ASSERT(texComponents
>= logComponents
);
633 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
634 * texComponents
* sizeof(GLchan
));
640 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
642 n
= srcWidth
* srcHeight
* srcDepth
;
643 for (i
= 0; i
< n
; i
++) {
645 for (k
= 0; k
< texComponents
; k
++) {
648 newImage
[i
* texComponents
+ k
] = 0;
650 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
652 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
657 tempImage
= newImage
;
665 * Copy GLubyte pixels from <src> to <dst> with swizzling.
666 * \param dst destination pixels
667 * \param dstComponents number of color components in destination pixels
668 * \param src source pixels
669 * \param srcComponents number of color components in source pixels
670 * \param map the swizzle mapping. map[X] says where to find the X component
671 * in the source image's pixels. For example, if the source image
672 * is GL_BGRA and X = red, map[0] yields 2.
673 * \param count number of pixels to copy/swizzle.
676 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
677 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
679 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
682 for (i = 0; i < count; i++) { \
684 if (srcComps == 4) { \
685 COPY_4UBV(tmp, src); \
688 for (j = 0; j < srcComps; j++) { \
693 for (j = 0; j < dstComps; j++) { \
694 dst[j] = tmp[map[j]]; \
705 ASSERT(srcComponents
<= 4);
706 ASSERT(dstComponents
<= 4);
708 switch (dstComponents
) {
710 switch (srcComponents
) {
712 SWZ_CPY(dst
, src
, count
, 4, 4);
715 SWZ_CPY(dst
, src
, count
, 4, 3);
718 SWZ_CPY(dst
, src
, count
, 4, 2);
721 SWZ_CPY(dst
, src
, count
, 4, 1);
728 switch (srcComponents
) {
730 SWZ_CPY(dst
, src
, count
, 3, 4);
733 SWZ_CPY(dst
, src
, count
, 3, 3);
736 SWZ_CPY(dst
, src
, count
, 3, 2);
739 SWZ_CPY(dst
, src
, count
, 3, 1);
746 switch (srcComponents
) {
748 SWZ_CPY(dst
, src
, count
, 2, 4);
751 SWZ_CPY(dst
, src
, count
, 2, 3);
754 SWZ_CPY(dst
, src
, count
, 2, 2);
757 SWZ_CPY(dst
, src
, count
, 2, 1);
764 switch (srcComponents
) {
766 SWZ_CPY(dst
, src
, count
, 1, 4);
769 SWZ_CPY(dst
, src
, count
, 1, 3);
772 SWZ_CPY(dst
, src
, count
, 1, 2);
775 SWZ_CPY(dst
, src
, count
, 1, 1);
789 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
790 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
794 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
795 * mapping array depending on endianness.
797 static const GLubyte
*
798 type_mapping( GLenum srcType
)
802 case GL_UNSIGNED_BYTE
:
804 case GL_UNSIGNED_INT_8_8_8_8
:
805 return _mesa_little_endian() ? map_3210
: map_identity
;
806 case GL_UNSIGNED_INT_8_8_8_8_REV
:
807 return _mesa_little_endian() ? map_identity
: map_3210
;
815 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
816 * mapping array depending on pixelstore byte swapping state.
818 static const GLubyte
*
819 byteswap_mapping( GLboolean swapBytes
,
827 case GL_UNSIGNED_BYTE
:
829 case GL_UNSIGNED_INT_8_8_8_8
:
830 case GL_UNSIGNED_INT_8_8_8_8_REV
:
840 * Transfer a GLubyte texture image with component swizzling.
843 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
848 GLenum baseInternalFormat
,
850 const GLubyte
*rgba2dst
,
851 GLuint dstComponents
,
854 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
856 const GLuint
*dstImageOffsets
,
858 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
859 const GLvoid
*srcAddr
,
860 const struct gl_pixelstore_attrib
*srcPacking
)
862 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
863 const GLubyte
*srctype2ubyte
, *swap
;
864 GLubyte map
[4], src2base
[6], base2rgba
[6];
866 const GLint srcRowStride
=
867 _mesa_image_row_stride(srcPacking
, srcWidth
,
868 srcFormat
, GL_UNSIGNED_BYTE
);
869 const GLint srcImageStride
870 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
872 const GLubyte
*srcImage
873 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
874 srcWidth
, srcHeight
, srcFormat
,
875 GL_UNSIGNED_BYTE
, 0, 0, 0);
879 /* Translate from src->baseInternal->GL_RGBA->dst. This will
880 * correctly deal with RGBA->RGB->RGBA conversions where the final
881 * A value must be 0xff regardless of the incoming alpha values.
883 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
884 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
885 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
886 srctype2ubyte
= type_mapping(srcType
);
889 for (i
= 0; i
< 4; i
++)
890 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
892 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
894 if (srcComponents
== dstComponents
&&
895 srcRowStride
== dstRowStride
&&
896 srcRowStride
== srcWidth
* srcComponents
&&
898 /* 1 and 2D images only */
899 GLubyte
*dstImage
= (GLubyte
*) dstAddr
900 + dstYoffset
* dstRowStride
901 + dstXoffset
* dstComponents
;
902 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
903 srcWidth
* srcHeight
);
907 for (img
= 0; img
< srcDepth
; img
++) {
908 const GLubyte
*srcRow
= srcImage
;
909 GLubyte
*dstRow
= (GLubyte
*) dstAddr
910 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
911 + dstYoffset
* dstRowStride
912 + dstXoffset
* dstComponents
;
913 for (row
= 0; row
< srcHeight
; row
++) {
914 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
915 dstRow
+= dstRowStride
;
916 srcRow
+= srcRowStride
;
918 srcImage
+= srcImageStride
;
925 * Teximage storage routine for when a simple memcpy will do.
926 * No pixel transfer operations or special texel encodings allowed.
927 * 1D, 2D and 3D images supported.
930 memcpy_texture(struct gl_context
*ctx
,
934 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
936 const GLuint
*dstImageOffsets
,
937 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
938 GLenum srcFormat
, GLenum srcType
,
939 const GLvoid
*srcAddr
,
940 const struct gl_pixelstore_attrib
*srcPacking
)
942 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
944 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
945 srcWidth
, srcHeight
, srcFormat
, srcType
);
946 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
947 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
948 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
949 const GLint bytesPerRow
= srcWidth
* texelBytes
;
952 /* XXX update/re-enable for dstImageOffsets array */
953 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
954 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
955 GLubyte
*dstImage
= (GLubyte
*) dstAddr
956 + dstZoffset
* dstImageStride
957 + dstYoffset
* dstRowStride
958 + dstXoffset
* texelBytes
;
960 if (dstRowStride
== srcRowStride
&&
961 dstRowStride
== bytesPerRow
&&
962 ((dstImageStride
== srcImageStride
&&
963 dstImageStride
== bytesPerImage
) ||
966 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
971 for (img
= 0; img
< srcDepth
; img
++) {
972 const GLubyte
*srcRow
= srcImage
;
973 GLubyte
*dstRow
= dstImage
;
974 for (row
= 0; row
< srcHeight
; row
++) {
975 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
976 dstRow
+= dstRowStride
;
977 srcRow
+= srcRowStride
;
979 srcImage
+= srcImageStride
;
980 dstImage
+= dstImageStride
;
986 for (img
= 0; img
< srcDepth
; img
++) {
987 const GLubyte
*srcRow
= srcImage
;
988 GLubyte
*dstRow
= (GLubyte
*) dstAddr
989 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
990 + dstYoffset
* dstRowStride
991 + dstXoffset
* texelBytes
;
992 for (row
= 0; row
< srcHeight
; row
++) {
993 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
994 dstRow
+= dstRowStride
;
995 srcRow
+= srcRowStride
;
997 srcImage
+= srcImageStride
;
1004 * Store a 32-bit integer depth component texture image.
1007 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1009 const GLuint depthScale
= 0xffffffff;
1010 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1012 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1013 ASSERT(texelBytes
== sizeof(GLuint
));
1015 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1016 ctx
->Pixel
.DepthBias
== 0.0f
&&
1017 !srcPacking
->SwapBytes
&&
1018 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1019 srcFormat
== GL_DEPTH_COMPONENT
&&
1020 srcType
== GL_UNSIGNED_INT
) {
1021 /* simple memcpy path */
1022 memcpy_texture(ctx
, dims
,
1023 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1026 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1027 srcAddr
, srcPacking
);
1032 for (img
= 0; img
< srcDepth
; img
++) {
1033 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1034 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1035 + dstYoffset
* dstRowStride
1036 + dstXoffset
* texelBytes
;
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_x8_z24(TEXSTORE_PARAMS
)
1057 const GLuint depthScale
= 0xffffff;
1058 const GLuint texelBytes
= 4;
1061 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1066 for (img
= 0; img
< srcDepth
; img
++) {
1067 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1068 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1069 + dstYoffset
* dstRowStride
1070 + dstXoffset
* texelBytes
;
1071 for (row
= 0; row
< srcHeight
; row
++) {
1072 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1073 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1074 _mesa_unpack_depth_span(ctx
, srcWidth
,
1075 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1076 depthScale
, srcType
, src
, srcPacking
);
1077 dstRow
+= dstRowStride
;
1086 * Store a 24-bit integer depth component texture image.
1089 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1091 const GLuint depthScale
= 0xffffff;
1092 const GLuint texelBytes
= 4;
1095 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1100 for (img
= 0; img
< srcDepth
; img
++) {
1101 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1102 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1103 + dstYoffset
* dstRowStride
1104 + dstXoffset
* texelBytes
;
1105 for (row
= 0; row
< srcHeight
; row
++) {
1106 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1107 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1108 GLuint
*dst
= (GLuint
*) dstRow
;
1110 _mesa_unpack_depth_span(ctx
, srcWidth
,
1111 GL_UNSIGNED_INT
, dst
,
1112 depthScale
, srcType
, src
, srcPacking
);
1113 for (i
= 0; i
< srcWidth
; i
++)
1115 dstRow
+= dstRowStride
;
1124 * Store a 16-bit integer depth component texture image.
1127 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1129 const GLuint depthScale
= 0xffff;
1130 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1132 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1133 ASSERT(texelBytes
== sizeof(GLushort
));
1135 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1136 ctx
->Pixel
.DepthBias
== 0.0f
&&
1137 !srcPacking
->SwapBytes
&&
1138 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1139 srcFormat
== GL_DEPTH_COMPONENT
&&
1140 srcType
== GL_UNSIGNED_SHORT
) {
1141 /* simple memcpy path */
1142 memcpy_texture(ctx
, dims
,
1143 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1146 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1147 srcAddr
, srcPacking
);
1152 for (img
= 0; img
< srcDepth
; img
++) {
1153 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1154 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1155 + dstYoffset
* dstRowStride
1156 + dstXoffset
* texelBytes
;
1157 for (row
= 0; row
< srcHeight
; row
++) {
1158 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1159 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1160 GLushort
*dst16
= (GLushort
*) dstRow
;
1161 _mesa_unpack_depth_span(ctx
, srcWidth
,
1162 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1163 srcType
, src
, srcPacking
);
1164 dstRow
+= dstRowStride
;
1173 * Store an rgb565 or rgb565_rev texture image.
1176 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1178 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1179 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1181 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1182 dstFormat
== MESA_FORMAT_RGB565_REV
);
1183 ASSERT(texelBytes
== 2);
1185 if (!ctx
->_ImageTransferState
&&
1186 !srcPacking
->SwapBytes
&&
1187 dstFormat
== MESA_FORMAT_RGB565
&&
1188 baseInternalFormat
== GL_RGB
&&
1189 srcFormat
== GL_RGB
&&
1190 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1191 /* simple memcpy path */
1192 memcpy_texture(ctx
, dims
,
1193 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1196 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1197 srcAddr
, srcPacking
);
1199 else if (!ctx
->_ImageTransferState
&&
1200 !srcPacking
->SwapBytes
&&
1201 baseInternalFormat
== GL_RGB
&&
1202 srcFormat
== GL_RGB
&&
1203 srcType
== GL_UNSIGNED_BYTE
&&
1205 /* do optimized tex store */
1206 const GLint srcRowStride
=
1207 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1208 const GLubyte
*src
= (const GLubyte
*)
1209 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1210 srcFormat
, srcType
, 0, 0, 0);
1211 GLubyte
*dst
= (GLubyte
*) dstAddr
1212 + dstYoffset
* dstRowStride
1213 + dstXoffset
* texelBytes
;
1215 for (row
= 0; row
< srcHeight
; row
++) {
1216 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1217 GLushort
*dstUS
= (GLushort
*) dst
;
1218 /* check for byteswapped format */
1219 if (dstFormat
== MESA_FORMAT_RGB565
) {
1220 for (col
= 0; col
< srcWidth
; col
++) {
1221 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1226 for (col
= 0; col
< srcWidth
; col
++) {
1227 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1231 dst
+= dstRowStride
;
1232 src
+= srcRowStride
;
1237 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1240 srcWidth
, srcHeight
, srcDepth
,
1241 srcFormat
, srcType
, srcAddr
,
1243 const GLchan
*src
= tempImage
;
1244 GLint img
, row
, col
;
1247 for (img
= 0; img
< srcDepth
; img
++) {
1248 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1249 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1250 + dstYoffset
* dstRowStride
1251 + dstXoffset
* texelBytes
;
1252 for (row
= 0; row
< srcHeight
; row
++) {
1253 GLushort
*dstUS
= (GLushort
*) dstRow
;
1254 /* check for byteswapped format */
1255 if (dstFormat
== MESA_FORMAT_RGB565
) {
1256 for (col
= 0; col
< srcWidth
; col
++) {
1257 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1258 CHAN_TO_UBYTE(src
[GCOMP
]),
1259 CHAN_TO_UBYTE(src
[BCOMP
]) );
1264 for (col
= 0; col
< srcWidth
; col
++) {
1265 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1266 CHAN_TO_UBYTE(src
[GCOMP
]),
1267 CHAN_TO_UBYTE(src
[BCOMP
]) );
1271 dstRow
+= dstRowStride
;
1274 free((void *) tempImage
);
1281 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1284 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1286 const GLboolean littleEndian
= _mesa_little_endian();
1287 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1288 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1290 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1291 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1292 ASSERT(texelBytes
== 4);
1294 if (!ctx
->_ImageTransferState
&&
1295 !srcPacking
->SwapBytes
&&
1296 dstFormat
== MESA_FORMAT_RGBA8888
&&
1297 baseInternalFormat
== GL_RGBA
&&
1298 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1299 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1300 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1301 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1302 /* simple memcpy path */
1303 memcpy_texture(ctx
, dims
,
1304 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1307 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1308 srcAddr
, srcPacking
);
1310 else if (!ctx
->_ImageTransferState
&&
1311 !srcPacking
->SwapBytes
&&
1312 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1313 baseInternalFormat
== GL_RGBA
&&
1314 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1315 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1316 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1317 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1318 /* simple memcpy path */
1319 memcpy_texture(ctx
, dims
,
1320 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1323 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1324 srcAddr
, srcPacking
);
1326 else if (!ctx
->_ImageTransferState
&&
1327 (srcType
== GL_UNSIGNED_BYTE
||
1328 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1329 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1330 can_swizzle(baseInternalFormat
) &&
1331 can_swizzle(srcFormat
)) {
1335 /* dstmap - how to swizzle from RGBA to dst format:
1337 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1338 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1351 _mesa_swizzle_ubyte_image(ctx
, dims
,
1356 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1357 dstRowStride
, dstImageOffsets
,
1358 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1363 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1366 srcWidth
, srcHeight
, srcDepth
,
1367 srcFormat
, srcType
, srcAddr
,
1369 const GLchan
*src
= tempImage
;
1370 GLint img
, row
, col
;
1373 for (img
= 0; img
< srcDepth
; img
++) {
1374 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1375 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1376 + dstYoffset
* dstRowStride
1377 + dstXoffset
* texelBytes
;
1378 for (row
= 0; row
< srcHeight
; row
++) {
1379 GLuint
*dstUI
= (GLuint
*) dstRow
;
1380 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1381 for (col
= 0; col
< srcWidth
; col
++) {
1382 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1383 CHAN_TO_UBYTE(src
[GCOMP
]),
1384 CHAN_TO_UBYTE(src
[BCOMP
]),
1385 CHAN_TO_UBYTE(src
[ACOMP
]) );
1390 for (col
= 0; col
< srcWidth
; col
++) {
1391 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1392 CHAN_TO_UBYTE(src
[GCOMP
]),
1393 CHAN_TO_UBYTE(src
[BCOMP
]),
1394 CHAN_TO_UBYTE(src
[ACOMP
]) );
1398 dstRow
+= dstRowStride
;
1401 free((void *) tempImage
);
1408 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1410 const GLboolean littleEndian
= _mesa_little_endian();
1411 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1412 const GLenum baseFormat
= GL_RGBA
;
1414 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1415 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1416 dstFormat
== MESA_FORMAT_XRGB8888
||
1417 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1418 ASSERT(texelBytes
== 4);
1420 if (!ctx
->_ImageTransferState
&&
1421 !srcPacking
->SwapBytes
&&
1422 (dstFormat
== MESA_FORMAT_ARGB8888
||
1423 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1424 baseInternalFormat
== GL_RGBA
&&
1425 srcFormat
== GL_BGRA
&&
1426 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1427 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1428 /* simple memcpy path (little endian) */
1429 memcpy_texture(ctx
, dims
,
1430 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1433 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1434 srcAddr
, srcPacking
);
1436 else if (!ctx
->_ImageTransferState
&&
1437 !srcPacking
->SwapBytes
&&
1438 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1439 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1440 baseInternalFormat
== GL_RGBA
&&
1441 srcFormat
== GL_BGRA
&&
1442 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1443 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1444 /* simple memcpy path (big endian) */
1445 memcpy_texture(ctx
, dims
,
1446 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1449 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1450 srcAddr
, srcPacking
);
1452 else if (!ctx
->_ImageTransferState
&&
1453 !srcPacking
->SwapBytes
&&
1454 (dstFormat
== MESA_FORMAT_ARGB8888
||
1455 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1456 srcFormat
== GL_RGB
&&
1457 (baseInternalFormat
== GL_RGBA
||
1458 baseInternalFormat
== GL_RGB
) &&
1459 srcType
== GL_UNSIGNED_BYTE
) {
1461 for (img
= 0; img
< srcDepth
; img
++) {
1462 const GLint srcRowStride
=
1463 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1464 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1465 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1466 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1467 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1468 + dstYoffset
* dstRowStride
1469 + dstXoffset
* texelBytes
;
1470 for (row
= 0; row
< srcHeight
; row
++) {
1471 GLuint
*d4
= (GLuint
*) dstRow
;
1472 for (col
= 0; col
< srcWidth
; col
++) {
1473 d4
[col
] = PACK_COLOR_8888(0xff,
1474 srcRow
[col
* 3 + RCOMP
],
1475 srcRow
[col
* 3 + GCOMP
],
1476 srcRow
[col
* 3 + BCOMP
]);
1478 dstRow
+= dstRowStride
;
1479 srcRow
+= srcRowStride
;
1483 else if (!ctx
->_ImageTransferState
&&
1484 !srcPacking
->SwapBytes
&&
1485 dstFormat
== MESA_FORMAT_ARGB8888
&&
1486 srcFormat
== GL_RGBA
&&
1487 baseInternalFormat
== GL_RGBA
&&
1488 srcType
== GL_UNSIGNED_BYTE
) {
1489 /* same as above case, but src data has alpha too */
1490 GLint img
, row
, col
;
1491 /* For some reason, streaming copies to write-combined regions
1492 * are extremely sensitive to the characteristics of how the
1493 * source data is retrieved. By reordering the source reads to
1494 * be in-order, the speed of this operation increases by half.
1495 * Strangely the same isn't required for the RGB path, above.
1497 for (img
= 0; img
< srcDepth
; img
++) {
1498 const GLint srcRowStride
=
1499 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1500 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1501 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1502 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1503 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1504 + dstYoffset
* dstRowStride
1505 + dstXoffset
* texelBytes
;
1506 for (row
= 0; row
< srcHeight
; row
++) {
1507 GLuint
*d4
= (GLuint
*) dstRow
;
1508 for (col
= 0; col
< srcWidth
; col
++) {
1509 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1510 srcRow
[col
* 4 + RCOMP
],
1511 srcRow
[col
* 4 + GCOMP
],
1512 srcRow
[col
* 4 + BCOMP
]);
1514 dstRow
+= dstRowStride
;
1515 srcRow
+= srcRowStride
;
1519 else if (!ctx
->_ImageTransferState
&&
1520 (srcType
== GL_UNSIGNED_BYTE
||
1521 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1522 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1523 can_swizzle(baseInternalFormat
) &&
1524 can_swizzle(srcFormat
)) {
1528 /* dstmap - how to swizzle from RGBA to dst format:
1530 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1531 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1532 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1533 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1534 dstmap
[3] = 3; /* alpha */
1535 dstmap
[2] = 0; /* red */
1536 dstmap
[1] = 1; /* green */
1537 dstmap
[0] = 2; /* blue */
1540 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1541 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1542 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1543 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1550 _mesa_swizzle_ubyte_image(ctx
, dims
,
1555 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1558 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1563 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1566 srcWidth
, srcHeight
, srcDepth
,
1567 srcFormat
, srcType
, srcAddr
,
1569 const GLchan
*src
= tempImage
;
1570 GLint img
, row
, col
;
1573 for (img
= 0; img
< srcDepth
; img
++) {
1574 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1575 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1576 + dstYoffset
* dstRowStride
1577 + dstXoffset
* texelBytes
;
1578 for (row
= 0; row
< srcHeight
; row
++) {
1579 GLuint
*dstUI
= (GLuint
*) dstRow
;
1580 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1581 for (col
= 0; col
< srcWidth
; col
++) {
1582 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1583 CHAN_TO_UBYTE(src
[RCOMP
]),
1584 CHAN_TO_UBYTE(src
[GCOMP
]),
1585 CHAN_TO_UBYTE(src
[BCOMP
]) );
1589 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1590 for (col
= 0; col
< srcWidth
; col
++) {
1591 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1592 CHAN_TO_UBYTE(src
[RCOMP
]),
1593 CHAN_TO_UBYTE(src
[GCOMP
]),
1594 CHAN_TO_UBYTE(src
[BCOMP
]) );
1599 for (col
= 0; col
< srcWidth
; col
++) {
1600 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1601 CHAN_TO_UBYTE(src
[RCOMP
]),
1602 CHAN_TO_UBYTE(src
[GCOMP
]),
1603 CHAN_TO_UBYTE(src
[BCOMP
]) );
1607 dstRow
+= dstRowStride
;
1610 free((void *) tempImage
);
1617 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1619 const GLboolean littleEndian
= _mesa_little_endian();
1620 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1621 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1623 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1624 ASSERT(texelBytes
== 3);
1626 if (!ctx
->_ImageTransferState
&&
1627 !srcPacking
->SwapBytes
&&
1628 baseInternalFormat
== GL_RGB
&&
1629 srcFormat
== GL_BGR
&&
1630 srcType
== GL_UNSIGNED_BYTE
&&
1632 /* simple memcpy path */
1633 memcpy_texture(ctx
, dims
,
1634 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1637 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1638 srcAddr
, srcPacking
);
1640 else if (!ctx
->_ImageTransferState
&&
1641 !srcPacking
->SwapBytes
&&
1642 srcFormat
== GL_RGBA
&&
1643 srcType
== GL_UNSIGNED_BYTE
) {
1644 /* extract RGB from RGBA */
1645 GLint img
, row
, col
;
1646 for (img
= 0; img
< srcDepth
; img
++) {
1647 const GLint srcRowStride
=
1648 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1649 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1650 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1651 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1652 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1653 + dstYoffset
* dstRowStride
1654 + dstXoffset
* texelBytes
;
1655 for (row
= 0; row
< srcHeight
; row
++) {
1656 for (col
= 0; col
< srcWidth
; col
++) {
1657 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1658 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1659 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1661 dstRow
+= dstRowStride
;
1662 srcRow
+= srcRowStride
;
1666 else if (!ctx
->_ImageTransferState
&&
1667 srcType
== GL_UNSIGNED_BYTE
&&
1668 can_swizzle(baseInternalFormat
) &&
1669 can_swizzle(srcFormat
)) {
1673 /* dstmap - how to swizzle from RGBA to dst format:
1678 dstmap
[3] = ONE
; /* ? */
1680 _mesa_swizzle_ubyte_image(ctx
, dims
,
1685 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1686 dstRowStride
, dstImageOffsets
,
1687 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1692 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1695 srcWidth
, srcHeight
, srcDepth
,
1696 srcFormat
, srcType
, srcAddr
,
1698 const GLchan
*src
= (const GLchan
*) tempImage
;
1699 GLint img
, row
, col
;
1702 for (img
= 0; img
< srcDepth
; img
++) {
1703 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1704 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1705 + dstYoffset
* dstRowStride
1706 + dstXoffset
* texelBytes
;
1707 for (row
= 0; row
< srcHeight
; row
++) {
1710 for (col
= 0; col
< srcWidth
; col
++) {
1711 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1712 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1713 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1718 for (col
= 0; col
< srcWidth
; col
++) {
1719 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1720 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1721 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1726 for (col
= 0; col
< srcWidth
; col
++) {
1727 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1728 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1729 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1733 dstRow
+= dstRowStride
;
1736 free((void *) tempImage
);
1743 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1745 const GLboolean littleEndian
= _mesa_little_endian();
1746 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1747 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1749 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1750 ASSERT(texelBytes
== 3);
1752 if (!ctx
->_ImageTransferState
&&
1753 !srcPacking
->SwapBytes
&&
1754 baseInternalFormat
== GL_RGB
&&
1755 srcFormat
== GL_RGB
&&
1756 srcType
== GL_UNSIGNED_BYTE
&&
1758 /* simple memcpy path */
1759 memcpy_texture(ctx
, dims
,
1760 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1763 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1764 srcAddr
, srcPacking
);
1766 else if (!ctx
->_ImageTransferState
&&
1767 !srcPacking
->SwapBytes
&&
1768 srcFormat
== GL_RGBA
&&
1769 srcType
== GL_UNSIGNED_BYTE
) {
1770 /* extract BGR from RGBA */
1772 for (img
= 0; img
< srcDepth
; img
++) {
1773 const GLint srcRowStride
=
1774 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1775 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1776 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1777 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1778 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1779 + dstYoffset
* dstRowStride
1780 + dstXoffset
* texelBytes
;
1781 for (row
= 0; row
< srcHeight
; row
++) {
1782 for (col
= 0; col
< srcWidth
; col
++) {
1783 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1784 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1785 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1787 dstRow
+= dstRowStride
;
1788 srcRow
+= srcRowStride
;
1792 else if (!ctx
->_ImageTransferState
&&
1793 srcType
== GL_UNSIGNED_BYTE
&&
1794 can_swizzle(baseInternalFormat
) &&
1795 can_swizzle(srcFormat
)) {
1799 /* dstmap - how to swizzle from RGBA to dst format:
1804 dstmap
[3] = ONE
; /* ? */
1806 _mesa_swizzle_ubyte_image(ctx
, dims
,
1811 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1812 dstRowStride
, dstImageOffsets
,
1813 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1818 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1821 srcWidth
, srcHeight
, srcDepth
,
1822 srcFormat
, srcType
, srcAddr
,
1824 const GLchan
*src
= (const GLchan
*) tempImage
;
1825 GLint img
, row
, col
;
1828 for (img
= 0; img
< srcDepth
; img
++) {
1829 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1830 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1831 + dstYoffset
* dstRowStride
1832 + dstXoffset
* texelBytes
;
1833 for (row
= 0; row
< srcHeight
; row
++) {
1834 for (col
= 0; col
< srcWidth
; col
++) {
1835 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1836 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1837 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1840 dstRow
+= dstRowStride
;
1843 free((void *) tempImage
);
1850 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1852 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1853 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1855 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1856 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1857 ASSERT(texelBytes
== 2);
1859 if (!ctx
->_ImageTransferState
&&
1860 !srcPacking
->SwapBytes
&&
1861 dstFormat
== MESA_FORMAT_ARGB4444
&&
1862 baseInternalFormat
== GL_RGBA
&&
1863 srcFormat
== GL_BGRA
&&
1864 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1865 /* simple memcpy path */
1866 memcpy_texture(ctx
, dims
,
1867 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1870 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1871 srcAddr
, srcPacking
);
1875 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1878 srcWidth
, srcHeight
, srcDepth
,
1879 srcFormat
, srcType
, srcAddr
,
1881 const GLchan
*src
= tempImage
;
1882 GLint img
, row
, col
;
1885 for (img
= 0; img
< srcDepth
; img
++) {
1886 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1887 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1888 + dstYoffset
* dstRowStride
1889 + dstXoffset
* texelBytes
;
1890 for (row
= 0; row
< srcHeight
; row
++) {
1891 GLushort
*dstUS
= (GLushort
*) dstRow
;
1892 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1893 for (col
= 0; col
< srcWidth
; col
++) {
1894 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1895 CHAN_TO_UBYTE(src
[RCOMP
]),
1896 CHAN_TO_UBYTE(src
[GCOMP
]),
1897 CHAN_TO_UBYTE(src
[BCOMP
]) );
1902 for (col
= 0; col
< srcWidth
; col
++) {
1903 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1904 CHAN_TO_UBYTE(src
[RCOMP
]),
1905 CHAN_TO_UBYTE(src
[GCOMP
]),
1906 CHAN_TO_UBYTE(src
[BCOMP
]) );
1910 dstRow
+= dstRowStride
;
1913 free((void *) tempImage
);
1919 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1921 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1922 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1924 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1925 ASSERT(texelBytes
== 2);
1927 if (!ctx
->_ImageTransferState
&&
1928 !srcPacking
->SwapBytes
&&
1929 dstFormat
== MESA_FORMAT_RGBA5551
&&
1930 baseInternalFormat
== GL_RGBA
&&
1931 srcFormat
== GL_RGBA
&&
1932 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1933 /* simple memcpy path */
1934 memcpy_texture(ctx
, dims
,
1935 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1938 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1939 srcAddr
, srcPacking
);
1943 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1946 srcWidth
, srcHeight
, srcDepth
,
1947 srcFormat
, srcType
, srcAddr
,
1949 const GLchan
*src
=tempImage
;
1950 GLint img
, row
, col
;
1953 for (img
= 0; img
< srcDepth
; img
++) {
1954 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1955 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1956 + dstYoffset
* dstRowStride
1957 + dstXoffset
* texelBytes
;
1958 for (row
= 0; row
< srcHeight
; row
++) {
1959 GLushort
*dstUS
= (GLushort
*) dstRow
;
1960 for (col
= 0; col
< srcWidth
; col
++) {
1961 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1962 CHAN_TO_UBYTE(src
[GCOMP
]),
1963 CHAN_TO_UBYTE(src
[BCOMP
]),
1964 CHAN_TO_UBYTE(src
[ACOMP
]) );
1967 dstRow
+= dstRowStride
;
1970 free((void *) tempImage
);
1976 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1978 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1979 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1981 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1982 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1983 ASSERT(texelBytes
== 2);
1985 if (!ctx
->_ImageTransferState
&&
1986 !srcPacking
->SwapBytes
&&
1987 dstFormat
== MESA_FORMAT_ARGB1555
&&
1988 baseInternalFormat
== GL_RGBA
&&
1989 srcFormat
== GL_BGRA
&&
1990 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1991 /* simple memcpy path */
1992 memcpy_texture(ctx
, dims
,
1993 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1996 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1997 srcAddr
, srcPacking
);
2001 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2004 srcWidth
, srcHeight
, srcDepth
,
2005 srcFormat
, srcType
, srcAddr
,
2007 const GLchan
*src
=tempImage
;
2008 GLint img
, row
, col
;
2011 for (img
= 0; img
< srcDepth
; img
++) {
2012 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2013 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2014 + dstYoffset
* dstRowStride
2015 + dstXoffset
* texelBytes
;
2016 for (row
= 0; row
< srcHeight
; row
++) {
2017 GLushort
*dstUS
= (GLushort
*) dstRow
;
2018 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2019 for (col
= 0; col
< srcWidth
; col
++) {
2020 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
2021 CHAN_TO_UBYTE(src
[RCOMP
]),
2022 CHAN_TO_UBYTE(src
[GCOMP
]),
2023 CHAN_TO_UBYTE(src
[BCOMP
]) );
2028 for (col
= 0; col
< srcWidth
; col
++) {
2029 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2030 CHAN_TO_UBYTE(src
[RCOMP
]),
2031 CHAN_TO_UBYTE(src
[GCOMP
]),
2032 CHAN_TO_UBYTE(src
[BCOMP
]) );
2036 dstRow
+= dstRowStride
;
2039 free((void *) tempImage
);
2046 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2048 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2049 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2051 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2052 ASSERT(texelBytes
== 4);
2054 if (!ctx
->_ImageTransferState
&&
2055 !srcPacking
->SwapBytes
&&
2056 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2057 srcFormat
== GL_BGRA
&&
2058 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2059 baseInternalFormat
== GL_RGBA
) {
2060 /* simple memcpy path */
2061 memcpy_texture(ctx
, dims
,
2062 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2065 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2066 srcAddr
, srcPacking
);
2070 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2073 srcWidth
, srcHeight
, srcDepth
,
2074 srcFormat
, srcType
, srcAddr
,
2076 ctx
->_ImageTransferState
);
2077 const GLfloat
*src
= tempImage
;
2078 GLint img
, row
, col
;
2081 for (img
= 0; img
< srcDepth
; img
++) {
2082 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2083 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2084 + dstYoffset
* dstRowStride
2085 + dstXoffset
* texelBytes
;
2086 if (baseInternalFormat
== GL_RGBA
) {
2087 for (row
= 0; row
< srcHeight
; row
++) {
2088 GLuint
*dstUI
= (GLuint
*) dstRow
;
2089 for (col
= 0; col
< srcWidth
; col
++) {
2092 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2093 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2094 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2095 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2096 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2099 dstRow
+= dstRowStride
;
2101 } else if (baseInternalFormat
== GL_RGB
) {
2102 for (row
= 0; row
< srcHeight
; row
++) {
2103 GLuint
*dstUI
= (GLuint
*) dstRow
;
2104 for (col
= 0; col
< srcWidth
; col
++) {
2107 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2108 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2109 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2110 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2113 dstRow
+= dstRowStride
;
2119 free((void *) tempImage
);
2126 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2129 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2131 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2132 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2134 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2135 ASSERT(texelBytes
== 1);
2139 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2142 srcWidth
, srcHeight
, srcDepth
,
2143 srcFormat
, srcType
, srcAddr
,
2145 const GLchan
*src
= tempImage
;
2146 GLint img
, row
, col
;
2149 for (img
= 0; img
< srcDepth
; img
++) {
2150 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2151 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2152 + dstYoffset
* dstRowStride
2153 + dstXoffset
* texelBytes
;
2154 for (row
= 0; row
< srcHeight
; row
++) {
2155 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2156 for (col
= 0; col
< srcWidth
; col
++) {
2157 /* src[0] is luminance, src[1] is alpha */
2158 dstUS
[col
] = PACK_COLOR_44( CHAN_TO_UBYTE(src
[1]),
2159 CHAN_TO_UBYTE(src
[0]) );
2162 dstRow
+= dstRowStride
;
2165 free((void *) tempImage
);
2172 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2175 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2177 const GLboolean littleEndian
= _mesa_little_endian();
2178 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2179 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2181 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2182 dstFormat
== MESA_FORMAT_AL88_REV
||
2183 dstFormat
== MESA_FORMAT_RG88
||
2184 dstFormat
== MESA_FORMAT_RG88_REV
);
2185 ASSERT(texelBytes
== 2);
2187 if (!ctx
->_ImageTransferState
&&
2188 !srcPacking
->SwapBytes
&&
2189 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
2190 baseInternalFormat
== srcFormat
&&
2191 srcType
== GL_UNSIGNED_BYTE
&&
2193 /* simple memcpy path */
2194 memcpy_texture(ctx
, dims
,
2195 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2198 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2199 srcAddr
, srcPacking
);
2201 else if (!ctx
->_ImageTransferState
&&
2203 srcType
== GL_UNSIGNED_BYTE
&&
2204 can_swizzle(baseInternalFormat
) &&
2205 can_swizzle(srcFormat
)) {
2208 /* dstmap - how to swizzle from RGBA to dst format:
2210 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2211 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2212 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2222 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2223 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2232 dstmap
[2] = ZERO
; /* ? */
2233 dstmap
[3] = ONE
; /* ? */
2235 _mesa_swizzle_ubyte_image(ctx
, dims
,
2240 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2241 dstRowStride
, dstImageOffsets
,
2242 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2247 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2250 srcWidth
, srcHeight
, srcDepth
,
2251 srcFormat
, srcType
, srcAddr
,
2253 const GLchan
*src
= tempImage
;
2254 GLint img
, row
, col
;
2257 for (img
= 0; img
< srcDepth
; img
++) {
2258 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2259 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2260 + dstYoffset
* dstRowStride
2261 + dstXoffset
* texelBytes
;
2262 for (row
= 0; row
< srcHeight
; row
++) {
2263 GLushort
*dstUS
= (GLushort
*) dstRow
;
2264 if (dstFormat
== MESA_FORMAT_AL88
||
2265 dstFormat
== MESA_FORMAT_RG88
) {
2266 for (col
= 0; col
< srcWidth
; col
++) {
2267 /* src[0] is luminance, src[1] is alpha */
2268 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2269 CHAN_TO_UBYTE(src
[0]) );
2274 for (col
= 0; col
< srcWidth
; col
++) {
2275 /* src[0] is luminance, src[1] is alpha */
2276 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2277 CHAN_TO_UBYTE(src
[0]) );
2281 dstRow
+= dstRowStride
;
2284 free((void *) tempImage
);
2291 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2294 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2296 const GLboolean littleEndian
= _mesa_little_endian();
2297 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2298 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2300 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2301 dstFormat
== MESA_FORMAT_AL1616_REV
||
2302 dstFormat
== MESA_FORMAT_RG1616
||
2303 dstFormat
== MESA_FORMAT_RG1616_REV
);
2304 ASSERT(texelBytes
== 4);
2306 if (!ctx
->_ImageTransferState
&&
2307 !srcPacking
->SwapBytes
&&
2308 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2309 baseInternalFormat
== srcFormat
&&
2310 srcType
== GL_UNSIGNED_SHORT
&&
2312 /* simple memcpy path */
2313 memcpy_texture(ctx
, dims
,
2314 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2317 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2318 srcAddr
, srcPacking
);
2322 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2325 srcWidth
, srcHeight
, srcDepth
,
2326 srcFormat
, srcType
, srcAddr
,
2328 ctx
->_ImageTransferState
);
2329 const GLfloat
*src
= tempImage
;
2330 GLint img
, row
, col
;
2333 for (img
= 0; img
< srcDepth
; img
++) {
2334 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2335 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2336 + dstYoffset
* dstRowStride
2337 + dstXoffset
* texelBytes
;
2338 for (row
= 0; row
< srcHeight
; row
++) {
2339 GLuint
*dstUI
= (GLuint
*) dstRow
;
2340 if (dstFormat
== MESA_FORMAT_AL1616
||
2341 dstFormat
== MESA_FORMAT_RG1616
) {
2342 for (col
= 0; col
< srcWidth
; col
++) {
2345 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2346 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2347 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2352 for (col
= 0; col
< srcWidth
; col
++) {
2355 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2356 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2357 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2361 dstRow
+= dstRowStride
;
2364 free((void *) tempImage
);
2370 /* Texstore for R16, A16, L16, I16. */
2372 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2374 const GLboolean littleEndian
= _mesa_little_endian();
2375 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2376 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2378 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2379 dstFormat
== MESA_FORMAT_A16
||
2380 dstFormat
== MESA_FORMAT_L16
||
2381 dstFormat
== MESA_FORMAT_I16
);
2382 ASSERT(texelBytes
== 2);
2384 if (!ctx
->_ImageTransferState
&&
2385 !srcPacking
->SwapBytes
&&
2386 baseInternalFormat
== srcFormat
&&
2387 srcType
== GL_UNSIGNED_SHORT
&&
2389 /* simple memcpy path */
2390 memcpy_texture(ctx
, dims
,
2391 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2394 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2395 srcAddr
, srcPacking
);
2399 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2402 srcWidth
, srcHeight
, srcDepth
,
2403 srcFormat
, srcType
, srcAddr
,
2405 ctx
->_ImageTransferState
);
2406 const GLfloat
*src
= tempImage
;
2407 GLint img
, row
, col
;
2410 for (img
= 0; img
< srcDepth
; img
++) {
2411 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2412 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2413 + dstYoffset
* dstRowStride
2414 + dstXoffset
* texelBytes
;
2415 for (row
= 0; row
< srcHeight
; row
++) {
2416 GLushort
*dstUS
= (GLushort
*) dstRow
;
2417 for (col
= 0; col
< srcWidth
; col
++) {
2420 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2424 dstRow
+= dstRowStride
;
2427 free((void *) tempImage
);
2434 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2436 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2437 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2439 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2440 ASSERT(texelBytes
== 8);
2442 if (!ctx
->_ImageTransferState
&&
2443 !srcPacking
->SwapBytes
&&
2444 baseInternalFormat
== GL_RGBA
&&
2445 srcFormat
== GL_RGBA
&&
2446 srcType
== GL_UNSIGNED_SHORT
) {
2447 /* simple memcpy path */
2448 memcpy_texture(ctx
, dims
,
2449 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2452 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2453 srcAddr
, srcPacking
);
2457 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2460 srcWidth
, srcHeight
, srcDepth
,
2461 srcFormat
, srcType
, srcAddr
,
2463 ctx
->_ImageTransferState
);
2464 const GLfloat
*src
= tempImage
;
2465 GLint img
, row
, col
;
2468 for (img
= 0; img
< srcDepth
; img
++) {
2469 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2470 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2471 + dstYoffset
* dstRowStride
2472 + dstXoffset
* texelBytes
;
2473 for (row
= 0; row
< srcHeight
; row
++) {
2474 GLushort
*dstUS
= (GLushort
*) dstRow
;
2475 for (col
= 0; col
< srcWidth
; col
++) {
2476 GLushort r
, g
, b
, a
;
2478 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2479 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2480 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2481 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2488 dstRow
+= dstRowStride
;
2491 free((void *) tempImage
);
2498 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2500 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2501 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2503 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2504 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2506 if (!ctx
->_ImageTransferState
&&
2507 !srcPacking
->SwapBytes
&&
2508 baseInternalFormat
== GL_RGBA
&&
2509 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2510 srcFormat
== GL_RGBA
&&
2511 srcType
== GL_SHORT
) {
2512 /* simple memcpy path */
2513 memcpy_texture(ctx
, dims
,
2514 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2517 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2518 srcAddr
, srcPacking
);
2522 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2525 srcWidth
, srcHeight
, srcDepth
,
2526 srcFormat
, srcType
, srcAddr
,
2528 ctx
->_ImageTransferState
);
2529 const GLfloat
*src
= tempImage
;
2530 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2531 GLint img
, row
, col
;
2536 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2537 * 3 or 4 components/pixel here.
2539 for (img
= 0; img
< srcDepth
; img
++) {
2540 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2541 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2542 + dstYoffset
* dstRowStride
2543 + dstXoffset
* texelBytes
;
2544 for (row
= 0; row
< srcHeight
; row
++) {
2545 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2546 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2547 for (col
= 0; col
< srcWidth
; col
++) {
2549 for (c
= 0; c
< comps
; c
++) {
2551 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2552 dstRowS
[col
* comps
+ c
] = p
;
2555 dstRow
+= dstRowStride
;
2556 src
+= 4 * srcWidth
;
2558 for (col
= 0; col
< srcWidth
; col
++) {
2560 for (c
= 0; c
< comps
; c
++) {
2562 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2563 dstRowS
[col
* comps
+ c
] = p
;
2566 dstRow
+= dstRowStride
;
2567 src
+= 3 * srcWidth
;
2571 free((void *) tempImage
);
2578 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2580 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2581 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2583 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2584 ASSERT(texelBytes
== 1);
2586 if (!ctx
->_ImageTransferState
&&
2587 !srcPacking
->SwapBytes
&&
2588 baseInternalFormat
== GL_RGB
&&
2589 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2590 /* simple memcpy path */
2591 memcpy_texture(ctx
, dims
,
2592 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2595 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2596 srcAddr
, srcPacking
);
2600 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2603 srcWidth
, srcHeight
, srcDepth
,
2604 srcFormat
, srcType
, srcAddr
,
2606 const GLchan
*src
= tempImage
;
2607 GLint img
, row
, col
;
2610 for (img
= 0; img
< srcDepth
; img
++) {
2611 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2612 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2613 + dstYoffset
* dstRowStride
2614 + dstXoffset
* texelBytes
;
2615 for (row
= 0; row
< srcHeight
; row
++) {
2616 for (col
= 0; col
< srcWidth
; col
++) {
2617 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2618 CHAN_TO_UBYTE(src
[GCOMP
]),
2619 CHAN_TO_UBYTE(src
[BCOMP
]) );
2622 dstRow
+= dstRowStride
;
2625 free((void *) tempImage
);
2632 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2635 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2637 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2638 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2640 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2641 dstFormat
== MESA_FORMAT_L8
||
2642 dstFormat
== MESA_FORMAT_I8
||
2643 dstFormat
== MESA_FORMAT_R8
);
2644 ASSERT(texelBytes
== 1);
2646 if (!ctx
->_ImageTransferState
&&
2647 !srcPacking
->SwapBytes
&&
2648 baseInternalFormat
== srcFormat
&&
2649 srcType
== GL_UNSIGNED_BYTE
) {
2650 /* simple memcpy path */
2651 memcpy_texture(ctx
, dims
,
2652 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2655 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2656 srcAddr
, srcPacking
);
2658 else if (!ctx
->_ImageTransferState
&&
2659 srcType
== GL_UNSIGNED_BYTE
&&
2660 can_swizzle(baseInternalFormat
) &&
2661 can_swizzle(srcFormat
)) {
2664 /* dstmap - how to swizzle from RGBA to dst format:
2666 if (dstFormat
== MESA_FORMAT_A8
) {
2672 dstmap
[1] = ZERO
; /* ? */
2673 dstmap
[2] = ZERO
; /* ? */
2674 dstmap
[3] = ONE
; /* ? */
2676 _mesa_swizzle_ubyte_image(ctx
, dims
,
2681 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2682 dstRowStride
, dstImageOffsets
,
2683 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2688 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2691 srcWidth
, srcHeight
, srcDepth
,
2692 srcFormat
, srcType
, srcAddr
,
2694 const GLchan
*src
= tempImage
;
2695 GLint img
, row
, col
;
2698 for (img
= 0; img
< srcDepth
; img
++) {
2699 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2700 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2701 + dstYoffset
* dstRowStride
2702 + dstXoffset
* texelBytes
;
2703 for (row
= 0; row
< srcHeight
; row
++) {
2704 for (col
= 0; col
< srcWidth
; col
++) {
2705 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2707 dstRow
+= dstRowStride
;
2711 free((void *) tempImage
);
2719 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2721 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2723 (void) dims
; (void) baseInternalFormat
;
2724 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2725 ASSERT(texelBytes
== 1);
2726 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2728 if (!ctx
->_ImageTransferState
&&
2729 !srcPacking
->SwapBytes
&&
2730 srcFormat
== GL_COLOR_INDEX
&&
2731 srcType
== GL_UNSIGNED_BYTE
) {
2732 /* simple memcpy path */
2733 memcpy_texture(ctx
, dims
,
2734 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2737 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2738 srcAddr
, srcPacking
);
2743 for (img
= 0; img
< srcDepth
; img
++) {
2744 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2745 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2746 + dstYoffset
* dstRowStride
2747 + dstXoffset
* texelBytes
;
2748 for (row
= 0; row
< srcHeight
; row
++) {
2749 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2750 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2751 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2752 srcType
, src
, srcPacking
,
2753 ctx
->_ImageTransferState
);
2754 dstRow
+= dstRowStride
;
2763 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2766 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2768 const GLboolean littleEndian
= _mesa_little_endian();
2769 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2771 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2773 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2774 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2775 ASSERT(texelBytes
== 2);
2776 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2777 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2778 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2779 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2780 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2782 /* always just memcpy since no pixel transfer ops apply */
2783 memcpy_texture(ctx
, dims
,
2784 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2787 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2788 srcAddr
, srcPacking
);
2790 /* Check if we need byte swapping */
2791 /* XXX the logic here _might_ be wrong */
2792 if (srcPacking
->SwapBytes
^
2793 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2794 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2797 for (img
= 0; img
< srcDepth
; img
++) {
2798 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2799 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2800 + dstYoffset
* dstRowStride
2801 + dstXoffset
* texelBytes
;
2802 for (row
= 0; row
< srcHeight
; row
++) {
2803 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2804 dstRow
+= dstRowStride
;
2812 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2814 const GLboolean littleEndian
= _mesa_little_endian();
2815 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2817 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2818 ASSERT(texelBytes
== 2);
2819 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2820 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2821 (srcFormat
== GL_DUDV_ATI
));
2822 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2824 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2826 /* simple memcpy path */
2827 memcpy_texture(ctx
, dims
,
2828 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2831 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2832 srcAddr
, srcPacking
);
2834 else if (srcType
== GL_BYTE
) {
2837 /* dstmap - how to swizzle from RGBA to dst format:
2847 dstmap
[2] = ZERO
; /* ? */
2848 dstmap
[3] = ONE
; /* ? */
2850 _mesa_swizzle_ubyte_image(ctx
, dims
,
2851 GL_LUMINANCE_ALPHA
, /* hack */
2852 GL_UNSIGNED_BYTE
, /* hack */
2853 GL_LUMINANCE_ALPHA
, /* hack */
2855 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2856 dstRowStride
, dstImageOffsets
,
2857 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2861 /* general path - note this is defined for 2d textures only */
2862 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2863 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2864 srcFormat
, srcType
);
2865 GLbyte
*tempImage
, *dst
, *src
;
2868 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2869 * components
* sizeof(GLbyte
));
2873 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2874 srcWidth
, srcHeight
,
2879 for (row
= 0; row
< srcHeight
; row
++) {
2880 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2881 dst
, srcFormat
, srcType
, src
,
2883 dst
+= srcWidth
* components
;
2888 dst
= (GLbyte
*) dstAddr
2889 + dstYoffset
* dstRowStride
2890 + dstXoffset
* texelBytes
;
2891 for (row
= 0; row
< srcHeight
; row
++) {
2892 memcpy(dst
, src
, srcWidth
* texelBytes
);
2893 dst
+= dstRowStride
;
2894 src
+= srcWidth
* texelBytes
;
2896 free((void *) tempImage
);
2903 * Store a texture in a signed normalized 8-bit format.
2906 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2908 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2909 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2911 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2912 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2913 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2914 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2915 ASSERT(texelBytes
== 1);
2917 if (!ctx
->_ImageTransferState
&&
2918 !srcPacking
->SwapBytes
&&
2919 baseInternalFormat
== srcFormat
&&
2920 srcType
== GL_BYTE
) {
2921 /* simple memcpy path */
2922 memcpy_texture(ctx
, dims
,
2923 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2926 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2927 srcAddr
, srcPacking
);
2931 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2934 srcWidth
, srcHeight
, srcDepth
,
2935 srcFormat
, srcType
, srcAddr
,
2937 ctx
->_ImageTransferState
);
2938 const GLfloat
*src
= tempImage
;
2939 GLint img
, row
, col
;
2942 for (img
= 0; img
< srcDepth
; img
++) {
2943 GLbyte
*dstRow
= (GLbyte
*) dstAddr
2944 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2945 + dstYoffset
* dstRowStride
2946 + dstXoffset
* texelBytes
;
2947 for (row
= 0; row
< srcHeight
; row
++) {
2948 for (col
= 0; col
< srcWidth
; col
++) {
2949 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2951 dstRow
+= dstRowStride
;
2955 free((void *) tempImage
);
2962 * Store a texture in a signed normalized two-channel 16-bit format.
2965 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2967 const GLboolean littleEndian
= _mesa_little_endian();
2968 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2969 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2971 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2972 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2973 ASSERT(texelBytes
== 2);
2975 if (!ctx
->_ImageTransferState
&&
2976 !srcPacking
->SwapBytes
&&
2977 baseInternalFormat
== srcFormat
&&
2978 srcType
== GL_BYTE
&&
2980 /* simple memcpy path */
2981 memcpy_texture(ctx
, dims
,
2982 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2985 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2986 srcAddr
, srcPacking
);
2990 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2993 srcWidth
, srcHeight
, srcDepth
,
2994 srcFormat
, srcType
, srcAddr
,
2996 ctx
->_ImageTransferState
);
2997 const GLfloat
*src
= tempImage
;
2998 GLint img
, row
, col
;
3001 for (img
= 0; img
< srcDepth
; img
++) {
3002 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3003 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3004 + dstYoffset
* dstRowStride
3005 + dstXoffset
* texelBytes
;
3006 for (row
= 0; row
< srcHeight
; row
++) {
3007 GLbyte
*dst
= dstRow
;
3008 for (col
= 0; col
< srcWidth
; col
++) {
3009 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
3010 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
3014 dstRow
+= dstRowStride
;
3017 free((void *) tempImage
);
3022 /* Texstore for signed R16, A16, L16, I16. */
3024 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
3026 const GLboolean littleEndian
= _mesa_little_endian();
3027 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3028 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3030 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
3031 dstFormat
== MESA_FORMAT_SIGNED_A16
||
3032 dstFormat
== MESA_FORMAT_SIGNED_L16
||
3033 dstFormat
== MESA_FORMAT_SIGNED_I16
);
3034 ASSERT(texelBytes
== 2);
3036 if (!ctx
->_ImageTransferState
&&
3037 !srcPacking
->SwapBytes
&&
3038 baseInternalFormat
== srcFormat
&&
3039 srcType
== GL_SHORT
&&
3041 /* simple memcpy path */
3042 memcpy_texture(ctx
, dims
,
3043 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3046 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3047 srcAddr
, srcPacking
);
3051 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3054 srcWidth
, srcHeight
, srcDepth
,
3055 srcFormat
, srcType
, srcAddr
,
3057 ctx
->_ImageTransferState
);
3058 const GLfloat
*src
= tempImage
;
3059 GLint img
, row
, col
;
3062 for (img
= 0; img
< srcDepth
; img
++) {
3063 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3064 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3065 + dstYoffset
* dstRowStride
3066 + dstXoffset
* texelBytes
;
3067 for (row
= 0; row
< srcHeight
; row
++) {
3068 GLshort
*dstUS
= (GLshort
*) dstRow
;
3069 for (col
= 0; col
< srcWidth
; col
++) {
3072 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
3076 dstRow
+= dstRowStride
;
3079 free((void *) tempImage
);
3085 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
3088 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
3090 const GLboolean littleEndian
= _mesa_little_endian();
3091 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3092 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3094 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
3095 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
3096 ASSERT(texelBytes
== 4);
3098 if (!ctx
->_ImageTransferState
&&
3099 !srcPacking
->SwapBytes
&&
3100 baseInternalFormat
== srcFormat
&&
3101 srcType
== GL_SHORT
&&
3103 /* simple memcpy path */
3104 memcpy_texture(ctx
, dims
,
3105 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3108 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3109 srcAddr
, srcPacking
);
3113 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3116 srcWidth
, srcHeight
, srcDepth
,
3117 srcFormat
, srcType
, srcAddr
,
3119 ctx
->_ImageTransferState
);
3120 const GLfloat
*src
= tempImage
;
3121 GLint img
, row
, col
;
3124 for (img
= 0; img
< srcDepth
; img
++) {
3125 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3126 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3127 + dstYoffset
* dstRowStride
3128 + dstXoffset
* texelBytes
;
3129 for (row
= 0; row
< srcHeight
; row
++) {
3130 GLshort
*dst
= (GLshort
*) dstRow
;
3131 for (col
= 0; col
< srcWidth
; col
++) {
3134 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
3135 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
3141 dstRow
+= dstRowStride
;
3144 free((void *) tempImage
);
3150 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
3153 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
3155 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3156 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3158 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
3159 ASSERT(texelBytes
== 4);
3163 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3166 srcWidth
, srcHeight
, srcDepth
,
3167 srcFormat
, srcType
, srcAddr
,
3169 ctx
->_ImageTransferState
);
3170 const GLfloat
*srcRow
= tempImage
;
3171 GLint img
, row
, col
;
3174 for (img
= 0; img
< srcDepth
; img
++) {
3175 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3176 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3177 + dstYoffset
* dstRowStride
3178 + dstXoffset
* texelBytes
;
3179 for (row
= 0; row
< srcHeight
; row
++) {
3180 GLbyte
*dst
= dstRow
;
3181 for (col
= 0; col
< srcWidth
; col
++) {
3182 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3183 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3184 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3189 dstRow
+= dstRowStride
;
3192 free((void *) tempImage
);
3200 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3201 * MESA_FORMAT_SIGNED_RGBA8888_REV
3204 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3206 const GLboolean littleEndian
= _mesa_little_endian();
3207 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3208 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3210 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3211 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3212 ASSERT(texelBytes
== 4);
3214 if (!ctx
->_ImageTransferState
&&
3215 !srcPacking
->SwapBytes
&&
3216 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3217 baseInternalFormat
== GL_RGBA
&&
3218 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3219 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3220 /* simple memcpy path */
3221 memcpy_texture(ctx
, dims
,
3222 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3225 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3226 srcAddr
, srcPacking
);
3228 else if (!ctx
->_ImageTransferState
&&
3229 !srcPacking
->SwapBytes
&&
3230 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3231 baseInternalFormat
== GL_RGBA
&&
3232 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3233 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3234 /* simple memcpy path */
3235 memcpy_texture(ctx
, dims
,
3236 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3239 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3240 srcAddr
, srcPacking
);
3244 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3247 srcWidth
, srcHeight
, srcDepth
,
3248 srcFormat
, srcType
, srcAddr
,
3250 ctx
->_ImageTransferState
);
3251 const GLfloat
*srcRow
= tempImage
;
3252 GLint img
, row
, col
;
3255 for (img
= 0; img
< srcDepth
; img
++) {
3256 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3257 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3258 + dstYoffset
* dstRowStride
3259 + dstXoffset
* texelBytes
;
3260 for (row
= 0; row
< srcHeight
; row
++) {
3261 GLbyte
*dst
= dstRow
;
3262 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3263 for (col
= 0; col
< srcWidth
; col
++) {
3264 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3265 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3266 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3267 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3273 for (col
= 0; col
< srcWidth
; col
++) {
3274 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3275 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3276 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3277 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3282 dstRow
+= dstRowStride
;
3285 free((void *) tempImage
);
3292 * Store a combined depth/stencil texture image.
3295 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3297 const GLuint depthScale
= 0xffffff;
3298 const GLint srcRowStride
3299 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3303 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3304 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
3305 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3307 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3308 ctx
->Pixel
.DepthBias
== 0.0f
&&
3309 !srcPacking
->SwapBytes
) {
3311 memcpy_texture(ctx
, dims
,
3312 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3315 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3316 srcAddr
, srcPacking
);
3318 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
3319 /* In case we only upload depth we need to preserve the stencil */
3320 for (img
= 0; img
< srcDepth
; img
++) {
3321 GLuint
*dstRow
= (GLuint
*) dstAddr
3322 + dstImageOffsets
[dstZoffset
+ img
]
3323 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3326 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3327 srcWidth
, srcHeight
,
3330 for (row
= 0; row
< srcHeight
; row
++) {
3331 GLuint depth
[MAX_WIDTH
];
3332 GLubyte stencil
[MAX_WIDTH
];
3334 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3336 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3337 keepstencil
= GL_TRUE
;
3339 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3340 keepdepth
= GL_TRUE
;
3343 if (keepdepth
== GL_FALSE
)
3344 /* the 24 depth bits will be in the low position: */
3345 _mesa_unpack_depth_span(ctx
, srcWidth
,
3346 GL_UNSIGNED_INT
, /* dst type */
3347 keepstencil
? depth
: dstRow
, /* dst addr */
3349 srcType
, src
, srcPacking
);
3351 if (keepstencil
== GL_FALSE
)
3352 /* get the 8-bit stencil values */
3353 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3354 GL_UNSIGNED_BYTE
, /* dst type */
3355 stencil
, /* dst addr */
3356 srcType
, src
, srcPacking
,
3357 ctx
->_ImageTransferState
);
3359 for (i
= 0; i
< srcWidth
; i
++) {
3361 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3363 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3366 src
+= srcRowStride
;
3367 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3376 * Store a combined depth/stencil texture image.
3379 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3381 const GLuint depthScale
= 0xffffff;
3382 const GLint srcRowStride
3383 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3387 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3388 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3389 srcFormat
== GL_DEPTH_COMPONENT
||
3390 srcFormat
== GL_STENCIL_INDEX
);
3391 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3392 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3394 for (img
= 0; img
< srcDepth
; img
++) {
3395 GLuint
*dstRow
= (GLuint
*) dstAddr
3396 + dstImageOffsets
[dstZoffset
+ img
]
3397 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3400 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3401 srcWidth
, srcHeight
,
3404 for (row
= 0; row
< srcHeight
; row
++) {
3405 GLuint depth
[MAX_WIDTH
];
3406 GLubyte stencil
[MAX_WIDTH
];
3408 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3410 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3411 keepstencil
= GL_TRUE
;
3413 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3414 keepdepth
= GL_TRUE
;
3417 if (keepdepth
== GL_FALSE
)
3418 /* the 24 depth bits will be in the low position: */
3419 _mesa_unpack_depth_span(ctx
, srcWidth
,
3420 GL_UNSIGNED_INT
, /* dst type */
3421 keepstencil
? depth
: dstRow
, /* dst addr */
3423 srcType
, src
, srcPacking
);
3425 if (keepstencil
== GL_FALSE
)
3426 /* get the 8-bit stencil values */
3427 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3428 GL_UNSIGNED_BYTE
, /* dst type */
3429 stencil
, /* dst addr */
3430 srcType
, src
, srcPacking
,
3431 ctx
->_ImageTransferState
);
3433 /* merge stencil values into depth values */
3434 for (i
= 0; i
< srcWidth
; i
++) {
3436 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3438 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3441 src
+= srcRowStride
;
3442 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3450 * Store simple 8-bit/value stencil texture data.
3453 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3455 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3456 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3458 if (!ctx
->_ImageTransferState
&&
3459 !srcPacking
->SwapBytes
&&
3460 baseInternalFormat
== srcFormat
&&
3461 srcType
== GL_UNSIGNED_BYTE
) {
3462 /* simple memcpy path */
3463 memcpy_texture(ctx
, dims
,
3464 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3467 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3468 srcAddr
, srcPacking
);
3471 const GLint srcRowStride
3472 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3476 for (img
= 0; img
< srcDepth
; img
++) {
3477 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3478 + dstImageOffsets
[dstZoffset
+ img
]
3479 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3482 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3483 srcWidth
, srcHeight
,
3486 for (row
= 0; row
< srcHeight
; row
++) {
3487 GLubyte stencil
[MAX_WIDTH
];
3490 /* get the 8-bit stencil values */
3491 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3492 GL_UNSIGNED_BYTE
, /* dst type */
3493 stencil
, /* dst addr */
3494 srcType
, src
, srcPacking
,
3495 ctx
->_ImageTransferState
);
3496 /* merge stencil values into depth values */
3497 for (i
= 0; i
< srcWidth
; i
++)
3498 dstRow
[i
] = stencil
[i
];
3500 src
+= srcRowStride
;
3501 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3512 * Store an image in any of the formats:
3513 * _mesa_texformat_rgba_float32
3514 * _mesa_texformat_rgb_float32
3515 * _mesa_texformat_alpha_float32
3516 * _mesa_texformat_luminance_float32
3517 * _mesa_texformat_luminance_alpha_float32
3518 * _mesa_texformat_intensity_float32
3521 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3523 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3524 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3525 const GLint components
= _mesa_components_in_format(baseFormat
);
3527 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3528 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3529 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3530 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3531 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3532 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3533 ASSERT(baseInternalFormat
== GL_RGBA
||
3534 baseInternalFormat
== GL_RGB
||
3535 baseInternalFormat
== GL_ALPHA
||
3536 baseInternalFormat
== GL_LUMINANCE
||
3537 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3538 baseInternalFormat
== GL_INTENSITY
);
3539 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3541 if (!ctx
->_ImageTransferState
&&
3542 !srcPacking
->SwapBytes
&&
3543 baseInternalFormat
== srcFormat
&&
3544 srcType
== GL_FLOAT
) {
3545 /* simple memcpy path */
3546 memcpy_texture(ctx
, dims
,
3547 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3550 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3551 srcAddr
, srcPacking
);
3555 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3558 srcWidth
, srcHeight
, srcDepth
,
3559 srcFormat
, srcType
, srcAddr
,
3561 ctx
->_ImageTransferState
);
3562 const GLfloat
*srcRow
= tempImage
;
3567 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3568 for (img
= 0; img
< srcDepth
; img
++) {
3569 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3570 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3571 + dstYoffset
* dstRowStride
3572 + dstXoffset
* texelBytes
;
3573 for (row
= 0; row
< srcHeight
; row
++) {
3574 memcpy(dstRow
, srcRow
, bytesPerRow
);
3575 dstRow
+= dstRowStride
;
3576 srcRow
+= srcWidth
* components
;
3580 free((void *) tempImage
);
3588 * As above, but store 16-bit floats.
3591 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3593 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3594 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3595 const GLint components
= _mesa_components_in_format(baseFormat
);
3597 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3598 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3599 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3600 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3601 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3602 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3603 ASSERT(baseInternalFormat
== GL_RGBA
||
3604 baseInternalFormat
== GL_RGB
||
3605 baseInternalFormat
== GL_ALPHA
||
3606 baseInternalFormat
== GL_LUMINANCE
||
3607 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3608 baseInternalFormat
== GL_INTENSITY
);
3609 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3611 if (!ctx
->_ImageTransferState
&&
3612 !srcPacking
->SwapBytes
&&
3613 baseInternalFormat
== srcFormat
&&
3614 srcType
== GL_HALF_FLOAT_ARB
) {
3615 /* simple memcpy path */
3616 memcpy_texture(ctx
, dims
,
3617 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3620 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3621 srcAddr
, srcPacking
);
3625 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3628 srcWidth
, srcHeight
, srcDepth
,
3629 srcFormat
, srcType
, srcAddr
,
3631 ctx
->_ImageTransferState
);
3632 const GLfloat
*src
= tempImage
;
3636 for (img
= 0; img
< srcDepth
; img
++) {
3637 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3638 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3639 + dstYoffset
* dstRowStride
3640 + dstXoffset
* texelBytes
;
3641 for (row
= 0; row
< srcHeight
; row
++) {
3642 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3644 for (i
= 0; i
< srcWidth
* components
; i
++) {
3645 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3647 dstRow
+= dstRowStride
;
3648 src
+= srcWidth
* components
;
3652 free((void *) tempImage
);
3658 /* non-normalized, signed int8 */
3660 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3662 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3663 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3664 const GLint components
= _mesa_components_in_format(baseFormat
);
3666 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3667 ASSERT(baseInternalFormat
== GL_RGBA
||
3668 baseInternalFormat
== GL_RGB
||
3669 baseInternalFormat
== GL_ALPHA
||
3670 baseInternalFormat
== GL_LUMINANCE
||
3671 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3672 baseInternalFormat
== GL_INTENSITY
);
3673 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3675 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3676 * to integer formats.
3678 if (!srcPacking
->SwapBytes
&&
3679 baseInternalFormat
== srcFormat
&&
3680 srcType
== GL_BYTE
) {
3681 /* simple memcpy path */
3682 memcpy_texture(ctx
, dims
,
3683 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3686 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3687 srcAddr
, srcPacking
);
3691 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3694 srcWidth
, srcHeight
, srcDepth
,
3695 srcFormat
, srcType
, srcAddr
,
3697 const GLfloat
*src
= tempImage
;
3701 for (img
= 0; img
< srcDepth
; img
++) {
3702 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3703 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3704 + dstYoffset
* dstRowStride
3705 + dstXoffset
* texelBytes
;
3706 for (row
= 0; row
< srcHeight
; row
++) {
3707 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3709 for (i
= 0; i
< srcWidth
* components
; i
++) {
3710 dstTexel
[i
] = (GLbyte
) src
[i
];
3712 dstRow
+= dstRowStride
;
3713 src
+= srcWidth
* components
;
3717 free((void *) tempImage
);
3723 /* non-normalized, signed int16 */
3725 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3727 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3728 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3729 const GLint components
= _mesa_components_in_format(baseFormat
);
3731 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3732 ASSERT(baseInternalFormat
== GL_RGBA
||
3733 baseInternalFormat
== GL_RGB
||
3734 baseInternalFormat
== GL_ALPHA
||
3735 baseInternalFormat
== GL_LUMINANCE
||
3736 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3737 baseInternalFormat
== GL_INTENSITY
);
3738 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3740 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3741 * to integer formats.
3743 if (!srcPacking
->SwapBytes
&&
3744 baseInternalFormat
== srcFormat
&&
3745 srcType
== GL_SHORT
) {
3746 /* simple memcpy path */
3747 memcpy_texture(ctx
, dims
,
3748 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3751 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3752 srcAddr
, srcPacking
);
3756 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3759 srcWidth
, srcHeight
, srcDepth
,
3760 srcFormat
, srcType
, srcAddr
,
3762 const GLfloat
*src
= tempImage
;
3766 for (img
= 0; img
< srcDepth
; img
++) {
3767 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3768 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3769 + dstYoffset
* dstRowStride
3770 + dstXoffset
* texelBytes
;
3771 for (row
= 0; row
< srcHeight
; row
++) {
3772 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3774 for (i
= 0; i
< srcWidth
* components
; i
++) {
3775 dstTexel
[i
] = (GLint
) src
[i
];
3777 dstRow
+= dstRowStride
;
3778 src
+= srcWidth
* components
;
3782 free((void *) tempImage
);
3788 /* non-normalized, signed int32 */
3790 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3792 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3793 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3794 const GLint components
= _mesa_components_in_format(baseFormat
);
3796 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3797 ASSERT(baseInternalFormat
== GL_RGBA
||
3798 baseInternalFormat
== GL_RGB
||
3799 baseInternalFormat
== GL_ALPHA
||
3800 baseInternalFormat
== GL_LUMINANCE
||
3801 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3802 baseInternalFormat
== GL_INTENSITY
);
3803 ASSERT(texelBytes
== components
* sizeof(GLint
));
3805 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3806 * to integer formats.
3808 if (!srcPacking
->SwapBytes
&&
3809 baseInternalFormat
== srcFormat
&&
3810 srcType
== GL_INT
) {
3811 /* simple memcpy path */
3812 memcpy_texture(ctx
, dims
,
3813 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3816 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3817 srcAddr
, srcPacking
);
3821 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3824 srcWidth
, srcHeight
, srcDepth
,
3825 srcFormat
, srcType
, srcAddr
,
3827 const GLfloat
*src
= tempImage
;
3831 for (img
= 0; img
< srcDepth
; img
++) {
3832 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3833 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3834 + dstYoffset
* dstRowStride
3835 + dstXoffset
* texelBytes
;
3836 for (row
= 0; row
< srcHeight
; row
++) {
3837 GLint
*dstTexel
= (GLint
*) dstRow
;
3839 for (i
= 0; i
< srcWidth
* components
; i
++) {
3840 dstTexel
[i
] = (GLint
) src
[i
];
3842 dstRow
+= dstRowStride
;
3843 src
+= srcWidth
* components
;
3847 free((void *) tempImage
);
3853 /* non-normalized, unsigned int8 */
3855 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3857 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3858 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3859 const GLint components
= _mesa_components_in_format(baseFormat
);
3861 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3862 ASSERT(baseInternalFormat
== GL_RGBA
||
3863 baseInternalFormat
== GL_RGB
||
3864 baseInternalFormat
== GL_ALPHA
||
3865 baseInternalFormat
== GL_LUMINANCE
||
3866 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3867 baseInternalFormat
== GL_INTENSITY
);
3868 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3870 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3871 * to integer formats.
3873 if (!srcPacking
->SwapBytes
&&
3874 baseInternalFormat
== srcFormat
&&
3875 srcType
== GL_UNSIGNED_BYTE
) {
3876 /* simple memcpy path */
3877 memcpy_texture(ctx
, dims
,
3878 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3881 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3882 srcAddr
, srcPacking
);
3886 const GLuint
*tempImage
=
3887 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3888 srcWidth
, srcHeight
, srcDepth
,
3889 srcFormat
, srcType
, srcAddr
, srcPacking
);
3890 const GLuint
*src
= tempImage
;
3894 for (img
= 0; img
< srcDepth
; img
++) {
3895 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3896 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3897 + dstYoffset
* dstRowStride
3898 + dstXoffset
* texelBytes
;
3899 for (row
= 0; row
< srcHeight
; row
++) {
3900 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3902 for (i
= 0; i
< srcWidth
* components
; i
++) {
3903 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3905 dstRow
+= dstRowStride
;
3906 src
+= srcWidth
* components
;
3910 free((void *) tempImage
);
3916 /* non-normalized, unsigned int16 */
3918 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3920 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3921 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3922 const GLint components
= _mesa_components_in_format(baseFormat
);
3924 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3925 ASSERT(baseInternalFormat
== GL_RGBA
||
3926 baseInternalFormat
== GL_RGB
||
3927 baseInternalFormat
== GL_ALPHA
||
3928 baseInternalFormat
== GL_LUMINANCE
||
3929 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3930 baseInternalFormat
== GL_INTENSITY
);
3931 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3933 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3934 * to integer formats.
3936 if (!srcPacking
->SwapBytes
&&
3937 baseInternalFormat
== srcFormat
&&
3938 srcType
== GL_UNSIGNED_SHORT
) {
3939 /* simple memcpy path */
3940 memcpy_texture(ctx
, dims
,
3941 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3944 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3945 srcAddr
, srcPacking
);
3949 const GLuint
*tempImage
=
3950 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3951 srcWidth
, srcHeight
, srcDepth
,
3952 srcFormat
, srcType
, srcAddr
, srcPacking
);
3953 const GLuint
*src
= tempImage
;
3957 for (img
= 0; img
< srcDepth
; img
++) {
3958 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3959 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3960 + dstYoffset
* dstRowStride
3961 + dstXoffset
* texelBytes
;
3962 for (row
= 0; row
< srcHeight
; row
++) {
3963 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3965 for (i
= 0; i
< srcWidth
* components
; i
++) {
3966 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3968 dstRow
+= dstRowStride
;
3969 src
+= srcWidth
* components
;
3973 free((void *) tempImage
);
3979 /* non-normalized, unsigned int32 */
3981 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3983 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3984 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3985 const GLint components
= _mesa_components_in_format(baseFormat
);
3987 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3988 ASSERT(baseInternalFormat
== GL_RGBA
||
3989 baseInternalFormat
== GL_RGB
||
3990 baseInternalFormat
== GL_ALPHA
||
3991 baseInternalFormat
== GL_LUMINANCE
||
3992 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3993 baseInternalFormat
== GL_INTENSITY
);
3994 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3996 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3997 * to integer formats.
3999 if (!srcPacking
->SwapBytes
&&
4000 baseInternalFormat
== srcFormat
&&
4001 srcType
== GL_UNSIGNED_INT
) {
4002 /* simple memcpy path */
4003 memcpy_texture(ctx
, dims
,
4004 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4007 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4008 srcAddr
, srcPacking
);
4012 const GLuint
*tempImage
=
4013 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
4014 srcWidth
, srcHeight
, srcDepth
,
4015 srcFormat
, srcType
, srcAddr
, srcPacking
);
4016 const GLuint
*src
= tempImage
;
4020 for (img
= 0; img
< srcDepth
; img
++) {
4021 GLubyte
*dstRow
= (GLubyte
*) dstAddr
4022 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
4023 + dstYoffset
* dstRowStride
4024 + dstXoffset
* texelBytes
;
4025 for (row
= 0; row
< srcHeight
; row
++) {
4026 GLuint
*dstTexel
= (GLuint
*) dstRow
;
4028 for (i
= 0; i
< srcWidth
* components
; i
++) {
4029 dstTexel
[i
] = src
[i
];
4031 dstRow
+= dstRowStride
;
4032 src
+= srcWidth
* components
;
4036 free((void *) tempImage
);
4044 #if FEATURE_EXT_texture_sRGB
4046 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
4048 gl_format newDstFormat
;
4051 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
4053 /* reuse normal rgb texstore code */
4054 newDstFormat
= MESA_FORMAT_RGB888
;
4056 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
4057 newDstFormat
, dstAddr
,
4058 dstXoffset
, dstYoffset
, dstZoffset
,
4059 dstRowStride
, dstImageOffsets
,
4060 srcWidth
, srcHeight
, srcDepth
,
4062 srcAddr
, srcPacking
);
4068 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
4070 gl_format newDstFormat
;
4073 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
4075 /* reuse normal rgba texstore code */
4076 newDstFormat
= MESA_FORMAT_RGBA8888
;
4077 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
4078 newDstFormat
, dstAddr
,
4079 dstXoffset
, dstYoffset
, dstZoffset
,
4080 dstRowStride
, dstImageOffsets
,
4081 srcWidth
, srcHeight
, srcDepth
,
4083 srcAddr
, srcPacking
);
4089 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
4091 gl_format newDstFormat
;
4094 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
4096 /* reuse normal rgba texstore code */
4097 newDstFormat
= MESA_FORMAT_ARGB8888
;
4099 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
4100 newDstFormat
, dstAddr
,
4101 dstXoffset
, dstYoffset
, dstZoffset
,
4102 dstRowStride
, dstImageOffsets
,
4103 srcWidth
, srcHeight
, srcDepth
,
4105 srcAddr
, srcPacking
);
4111 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
4113 gl_format newDstFormat
;
4116 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
4118 newDstFormat
= MESA_FORMAT_L8
;
4120 /* _mesa_textore_a8 handles luminance8 too */
4121 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
4122 newDstFormat
, dstAddr
,
4123 dstXoffset
, dstYoffset
, dstZoffset
,
4124 dstRowStride
, dstImageOffsets
,
4125 srcWidth
, srcHeight
, srcDepth
,
4127 srcAddr
, srcPacking
);
4133 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
4135 gl_format newDstFormat
;
4138 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4140 /* reuse normal luminance/alpha texstore code */
4141 newDstFormat
= MESA_FORMAT_AL88
;
4143 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4144 newDstFormat
, dstAddr
,
4145 dstXoffset
, dstYoffset
, dstZoffset
,
4146 dstRowStride
, dstImageOffsets
,
4147 srcWidth
, srcHeight
, srcDepth
,
4149 srcAddr
, srcPacking
);
4155 /* these are used only in texstore_funcs[] below */
4156 #define _mesa_texstore_srgb8 NULL
4157 #define _mesa_texstore_srgba8 NULL
4158 #define _mesa_texstore_sargb8 NULL
4159 #define _mesa_texstore_sl8 NULL
4160 #define _mesa_texstore_sla8 NULL
4162 #endif /* FEATURE_EXT_texture_sRGB */
4168 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4169 * XXX this is somewhat temporary.
4171 static const struct {
4173 StoreTexImageFunc Store
;
4175 texstore_funcs
[MESA_FORMAT_COUNT
] =
4177 { MESA_FORMAT_NONE
, NULL
},
4178 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
4179 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
4180 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
4181 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
4182 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
4183 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
4184 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
4185 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
4186 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
4187 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
4188 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
4189 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
4190 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
4191 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
4192 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
4193 { MESA_FORMAT_AL44
, _mesa_texstore_unorm44
},
4194 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
4195 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
4196 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
4197 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
4198 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
4199 { MESA_FORMAT_A8
, _mesa_texstore_unorm8
},
4200 { MESA_FORMAT_A16
, _mesa_texstore_unorm16
},
4201 { MESA_FORMAT_L8
, _mesa_texstore_unorm8
},
4202 { MESA_FORMAT_L16
, _mesa_texstore_unorm16
},
4203 { MESA_FORMAT_I8
, _mesa_texstore_unorm8
},
4204 { MESA_FORMAT_I16
, _mesa_texstore_unorm16
},
4205 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
4206 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
4207 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
4208 { MESA_FORMAT_R8
, _mesa_texstore_unorm8
},
4209 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
4210 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
4211 { MESA_FORMAT_R16
, _mesa_texstore_unorm16
},
4212 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
4213 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
4214 { MESA_FORMAT_ARGB2101010
, _mesa_texstore_argb2101010
},
4215 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
4216 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
4217 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
4218 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
4219 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
4220 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
4221 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
4222 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
4223 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
4224 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
4225 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
4226 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
4227 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4228 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4229 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4230 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4231 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
4232 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
4233 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4234 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4235 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4236 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4237 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
4238 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
4239 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
4240 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
4241 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4242 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4243 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
4244 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
4245 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4246 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4247 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
4248 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
4250 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
4251 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
4252 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
4253 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
4254 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
4255 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
4257 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
4259 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_snorm8
},
4260 { MESA_FORMAT_SIGNED_RG88_REV
, _mesa_texstore_snorm88
},
4261 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
4263 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
4264 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
4266 { MESA_FORMAT_SIGNED_R16
, _mesa_texstore_snorm16
},
4267 { MESA_FORMAT_SIGNED_GR1616
, _mesa_texstore_snorm1616
},
4268 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
4269 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
4270 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
},
4272 { MESA_FORMAT_RED_RGTC1
, _mesa_texstore_red_rgtc1
},
4273 { MESA_FORMAT_SIGNED_RED_RGTC1
, _mesa_texstore_signed_red_rgtc1
},
4274 { MESA_FORMAT_RG_RGTC2
, _mesa_texstore_rg_rgtc2
},
4275 { MESA_FORMAT_SIGNED_RG_RGTC2
, _mesa_texstore_signed_rg_rgtc2
},
4277 /* Re-use the R/RG texstore functions.
4278 * The code is generic enough to handle LATC too. */
4279 { MESA_FORMAT_L_LATC1
, _mesa_texstore_red_rgtc1
},
4280 { MESA_FORMAT_SIGNED_L_LATC1
, _mesa_texstore_signed_red_rgtc1
},
4281 { MESA_FORMAT_LA_LATC2
, _mesa_texstore_rg_rgtc2
},
4282 { MESA_FORMAT_SIGNED_LA_LATC2
, _mesa_texstore_signed_rg_rgtc2
},
4284 { MESA_FORMAT_SIGNED_A8
, _mesa_texstore_snorm8
},
4285 { MESA_FORMAT_SIGNED_L8
, _mesa_texstore_snorm8
},
4286 { MESA_FORMAT_SIGNED_AL88
, _mesa_texstore_snorm88
},
4287 { MESA_FORMAT_SIGNED_I8
, _mesa_texstore_snorm8
},
4289 { MESA_FORMAT_SIGNED_A16
, _mesa_texstore_snorm16
},
4290 { MESA_FORMAT_SIGNED_L16
, _mesa_texstore_snorm16
},
4291 { MESA_FORMAT_SIGNED_AL1616
, _mesa_texstore_snorm1616
},
4292 { MESA_FORMAT_SIGNED_I16
, _mesa_texstore_snorm16
},
4297 _mesa_texstore_null(TEXSTORE_PARAMS
)
4299 (void) ctx
; (void) dims
;
4300 (void) baseInternalFormat
;
4303 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4304 (void) dstRowStride
; (void) dstImageOffsets
;
4305 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4306 (void) srcFormat
; (void) srcType
;
4310 /* should never happen */
4311 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4317 * Return the StoreTexImageFunc pointer to store an image in the given format.
4319 static StoreTexImageFunc
4320 _mesa_get_texstore_func(gl_format format
)
4324 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4325 ASSERT(texstore_funcs
[i
].Name
== i
);
4328 ASSERT(texstore_funcs
[format
].Name
== format
);
4330 if (texstore_funcs
[format
].Store
)
4331 return texstore_funcs
[format
].Store
;
4333 return _mesa_texstore_null
;
4338 * Store user data into texture memory.
4339 * Called via glTex[Sub]Image1/2/3D()
4342 _mesa_texstore(TEXSTORE_PARAMS
)
4344 StoreTexImageFunc storeImage
;
4347 storeImage
= _mesa_get_texstore_func(dstFormat
);
4349 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4350 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4351 dstRowStride
, dstImageOffsets
,
4352 srcWidth
, srcHeight
, srcDepth
,
4353 srcFormat
, srcType
, srcAddr
, srcPacking
);
4358 /** Return texture size in bytes */
4360 texture_size(const struct gl_texture_image
*texImage
)
4362 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4363 texImage
->Height
, texImage
->Depth
);
4368 /** Return row stride in bytes */
4370 texture_row_stride(const struct gl_texture_image
*texImage
)
4372 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4380 * This is the software fallback for Driver.TexImage1D()
4381 * and Driver.CopyTexImage1D().
4382 * \sa _mesa_store_teximage2d()
4385 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4386 GLint internalFormat
,
4387 GLint width
, GLint border
,
4388 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4389 const struct gl_pixelstore_attrib
*packing
,
4390 struct gl_texture_object
*texObj
,
4391 struct gl_texture_image
*texImage
)
4396 /* allocate memory */
4397 sizeInBytes
= texture_size(texImage
);
4398 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4399 if (!texImage
->Data
) {
4400 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4404 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4405 pixels
, packing
, "glTexImage1D");
4407 /* Note: we check for a NULL image pointer here, _after_ we allocated
4408 * memory for the texture. That's what the GL spec calls for.
4413 const GLint dstRowStride
= 0;
4414 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4415 texImage
->TexFormat
,
4417 0, 0, 0, /* dstX/Y/Zoffset */
4419 texImage
->ImageOffsets
,
4421 format
, type
, pixels
, packing
);
4423 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4427 _mesa_unmap_teximage_pbo(ctx
, packing
);
4432 * This is the software fallback for Driver.TexImage2D()
4433 * and Driver.CopyTexImage2D().
4435 * This function is oriented toward storing images in main memory, rather
4436 * than VRAM. Device driver's can easily plug in their own replacement.
4439 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4440 GLint internalFormat
,
4441 GLint width
, GLint height
, GLint border
,
4442 GLenum format
, GLenum type
, const void *pixels
,
4443 const struct gl_pixelstore_attrib
*packing
,
4444 struct gl_texture_object
*texObj
,
4445 struct gl_texture_image
*texImage
)
4450 /* allocate memory */
4451 sizeInBytes
= texture_size(texImage
);
4452 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4453 if (!texImage
->Data
) {
4454 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4458 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4459 pixels
, packing
, "glTexImage2D");
4461 /* Note: we check for a NULL image pointer here, _after_ we allocated
4462 * memory for the texture. That's what the GL spec calls for.
4467 GLint dstRowStride
= texture_row_stride(texImage
);
4468 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4469 texImage
->TexFormat
,
4471 0, 0, 0, /* dstX/Y/Zoffset */
4473 texImage
->ImageOffsets
,
4475 format
, type
, pixels
, packing
);
4477 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4481 _mesa_unmap_teximage_pbo(ctx
, packing
);
4487 * This is the software fallback for Driver.TexImage3D()
4488 * and Driver.CopyTexImage3D().
4489 * \sa _mesa_store_teximage2d()
4492 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4493 GLint internalFormat
,
4494 GLint width
, GLint height
, GLint depth
, GLint border
,
4495 GLenum format
, GLenum type
, const void *pixels
,
4496 const struct gl_pixelstore_attrib
*packing
,
4497 struct gl_texture_object
*texObj
,
4498 struct gl_texture_image
*texImage
)
4503 /* allocate memory */
4504 sizeInBytes
= texture_size(texImage
);
4505 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4506 if (!texImage
->Data
) {
4507 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4511 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4512 type
, pixels
, packing
, "glTexImage3D");
4514 /* Note: we check for a NULL image pointer here, _after_ we allocated
4515 * memory for the texture. That's what the GL spec calls for.
4520 GLint dstRowStride
= texture_row_stride(texImage
);
4521 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4522 texImage
->TexFormat
,
4524 0, 0, 0, /* dstX/Y/Zoffset */
4526 texImage
->ImageOffsets
,
4527 width
, height
, depth
,
4528 format
, type
, pixels
, packing
);
4530 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4534 _mesa_unmap_teximage_pbo(ctx
, packing
);
4541 * This is the software fallback for Driver.TexSubImage1D()
4542 * and Driver.CopyTexSubImage1D().
4545 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4546 GLint xoffset
, GLint width
,
4547 GLenum format
, GLenum type
, const void *pixels
,
4548 const struct gl_pixelstore_attrib
*packing
,
4549 struct gl_texture_object
*texObj
,
4550 struct gl_texture_image
*texImage
)
4552 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4553 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4554 pixels
, packing
, "glTexSubImage1D");
4559 const GLint dstRowStride
= 0;
4560 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4561 texImage
->TexFormat
,
4563 xoffset
, 0, 0, /* offsets */
4565 texImage
->ImageOffsets
,
4567 format
, type
, pixels
, packing
);
4569 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4573 _mesa_unmap_teximage_pbo(ctx
, packing
);
4579 * This is the software fallback for Driver.TexSubImage2D()
4580 * and Driver.CopyTexSubImage2D().
4583 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4584 GLint xoffset
, GLint yoffset
,
4585 GLint width
, GLint height
,
4586 GLenum format
, GLenum type
, const void *pixels
,
4587 const struct gl_pixelstore_attrib
*packing
,
4588 struct gl_texture_object
*texObj
,
4589 struct gl_texture_image
*texImage
)
4591 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4592 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4593 pixels
, packing
, "glTexSubImage2D");
4598 GLint dstRowStride
= texture_row_stride(texImage
);
4599 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4600 texImage
->TexFormat
,
4602 xoffset
, yoffset
, 0,
4604 texImage
->ImageOffsets
,
4606 format
, type
, pixels
, packing
);
4608 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4612 _mesa_unmap_teximage_pbo(ctx
, packing
);
4617 * This is the software fallback for Driver.TexSubImage3D().
4618 * and Driver.CopyTexSubImage3D().
4621 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4622 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4623 GLint width
, GLint height
, GLint depth
,
4624 GLenum format
, GLenum type
, const void *pixels
,
4625 const struct gl_pixelstore_attrib
*packing
,
4626 struct gl_texture_object
*texObj
,
4627 struct gl_texture_image
*texImage
)
4629 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4630 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4631 type
, pixels
, packing
,
4637 GLint dstRowStride
= texture_row_stride(texImage
);
4638 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4639 texImage
->TexFormat
,
4641 xoffset
, yoffset
, zoffset
,
4643 texImage
->ImageOffsets
,
4644 width
, height
, depth
,
4645 format
, type
, pixels
, packing
);
4647 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4651 _mesa_unmap_teximage_pbo(ctx
, packing
);
4656 * Fallback for Driver.CompressedTexImage1D()
4659 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4660 GLenum target
, GLint level
,
4661 GLint internalFormat
,
4662 GLint width
, GLint border
,
4663 GLsizei imageSize
, const GLvoid
*data
,
4664 struct gl_texture_object
*texObj
,
4665 struct gl_texture_image
*texImage
)
4667 /* this space intentionally left blank */
4669 (void) target
; (void) level
;
4670 (void) internalFormat
;
4671 (void) width
; (void) border
;
4672 (void) imageSize
; (void) data
;
4680 * Fallback for Driver.CompressedTexImage2D()
4683 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4684 GLenum target
, GLint level
,
4685 GLint internalFormat
,
4686 GLint width
, GLint height
, GLint border
,
4687 GLsizei imageSize
, const GLvoid
*data
,
4688 struct gl_texture_object
*texObj
,
4689 struct gl_texture_image
*texImage
)
4691 (void) width
; (void) height
; (void) border
;
4693 /* This is pretty simple, basically just do a memcpy without worrying
4694 * about the usual image unpacking or image transfer operations.
4698 ASSERT(texImage
->Width
> 0);
4699 ASSERT(texImage
->Height
> 0);
4700 ASSERT(texImage
->Depth
== 1);
4701 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4703 /* allocate storage */
4704 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4705 if (!texImage
->Data
) {
4706 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4710 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4712 "glCompressedTexImage2D");
4717 memcpy(texImage
->Data
, data
, imageSize
);
4719 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4725 * Fallback for Driver.CompressedTexImage3D()
4728 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4729 GLenum target
, GLint level
,
4730 GLint internalFormat
,
4731 GLint width
, GLint height
, GLint depth
,
4733 GLsizei imageSize
, const GLvoid
*data
,
4734 struct gl_texture_object
*texObj
,
4735 struct gl_texture_image
*texImage
)
4737 /* this space intentionally left blank */
4739 (void) target
; (void) level
;
4740 (void) internalFormat
;
4741 (void) width
; (void) height
; (void) depth
;
4743 (void) imageSize
; (void) data
;
4751 * Fallback for Driver.CompressedTexSubImage1D()
4754 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4756 GLint xoffset
, GLsizei width
,
4758 GLsizei imageSize
, const GLvoid
*data
,
4759 struct gl_texture_object
*texObj
,
4760 struct gl_texture_image
*texImage
)
4762 /* there are no compressed 1D texture formats yet */
4764 (void) target
; (void) level
;
4765 (void) xoffset
; (void) width
;
4767 (void) imageSize
; (void) data
;
4774 * Fallback for Driver.CompressedTexSubImage2D()
4777 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4779 GLint xoffset
, GLint yoffset
,
4780 GLsizei width
, GLsizei height
,
4782 GLsizei imageSize
, const GLvoid
*data
,
4783 struct gl_texture_object
*texObj
,
4784 struct gl_texture_image
*texImage
)
4786 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4790 const gl_format texFormat
= texImage
->TexFormat
;
4791 const GLint destWidth
= texImage
->Width
;
4794 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4799 /* these should have been caught sooner */
4800 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4801 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4802 ASSERT((xoffset
% bw
) == 0);
4803 ASSERT((yoffset
% bh
) == 0);
4805 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4806 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4808 "glCompressedTexSubImage2D");
4812 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4813 src
= (const GLubyte
*) data
;
4815 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4816 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4817 texFormat
, destWidth
,
4818 (GLubyte
*) texImage
->Data
);
4820 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4821 rows
= height
/ bh
; /* rows in blocks */
4823 /* copy rows of blocks */
4824 for (i
= 0; i
< rows
; i
++) {
4825 memcpy(dest
, src
, bytesPerRow
);
4826 dest
+= destRowStride
;
4827 src
+= srcRowStride
;
4830 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4835 * Fallback for Driver.CompressedTexSubImage3D()
4838 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4840 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4841 GLsizei width
, GLsizei height
, GLsizei depth
,
4843 GLsizei imageSize
, const GLvoid
*data
,
4844 struct gl_texture_object
*texObj
,
4845 struct gl_texture_image
*texImage
)
4847 /* there are no compressed 3D texture formats yet */
4849 (void) target
; (void) level
;
4850 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4851 (void) width
; (void) height
; (void) depth
;
4853 (void) imageSize
; (void) data
;