2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
82 * Texture image storage function.
84 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
88 * Return GL_TRUE if the given image format is one that be converted
89 * to another format by swizzling.
92 can_swizzle(GLenum logicalBaseFormat
)
94 switch (logicalBaseFormat
) {
97 case GL_LUMINANCE_ALPHA
:
133 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
134 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
135 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
136 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
139 static const struct {
142 GLubyte from_rgba
[6];
143 } mappings
[MAX_IDX
] =
153 MAP4(ZERO
, ZERO
, ZERO
, 0),
183 MAP4(0, ZERO
, ZERO
, ONE
),
189 MAP4(ZERO
, 0, ZERO
, ONE
),
195 MAP4(ZERO
, ZERO
, 0, ONE
),
219 MAP4(0, 1, ZERO
, ONE
),
227 * Convert a GL image format enum to an IDX_* value (see above).
230 get_map_idx(GLenum value
)
233 case GL_LUMINANCE
: return IDX_LUMINANCE
;
234 case GL_ALPHA
: return IDX_ALPHA
;
235 case GL_INTENSITY
: return IDX_INTENSITY
;
236 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
237 case GL_RGB
: return IDX_RGB
;
238 case GL_RGBA
: return IDX_RGBA
;
239 case GL_RED
: return IDX_RED
;
240 case GL_GREEN
: return IDX_GREEN
;
241 case GL_BLUE
: return IDX_BLUE
;
242 case GL_BGR
: return IDX_BGR
;
243 case GL_BGRA
: return IDX_BGRA
;
244 case GL_ABGR_EXT
: return IDX_ABGR
;
245 case GL_RG
: return IDX_RG
;
247 _mesa_problem(NULL
, "Unexpected inFormat");
254 * When promoting texture formats (see below) we need to compute the
255 * mapping of dest components back to source components.
256 * This function does that.
257 * \param inFormat the incoming format of the texture
258 * \param outFormat the final texture format
259 * \return map[6] a full 6-component map
262 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
265 const int inFmt
= get_map_idx(inFormat
);
266 const int outFmt
= get_map_idx(outFormat
);
267 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
268 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
271 for (i
= 0; i
< 4; i
++)
272 map
[i
] = in2rgba
[rgba2out
[i
]];
278 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
279 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
280 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
292 * Make a temporary (color) texture image with GLfloat components.
293 * Apply all needed pixel unpacking and pixel transfer operations.
294 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
295 * Suppose the user specifies GL_LUMINANCE as the internal texture format
296 * but the graphics hardware doesn't support luminance textures. So, we might
297 * use an RGB hardware format instead.
298 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
300 * \param ctx the rendering context
301 * \param dims image dimensions: 1, 2 or 3
302 * \param logicalBaseFormat basic texture derived from the user's
303 * internal texture format value
304 * \param textureBaseFormat the actual basic format of the texture
305 * \param srcWidth source image width
306 * \param srcHeight source image height
307 * \param srcDepth source image depth
308 * \param srcFormat source image format
309 * \param srcType source image type
310 * \param srcAddr source image address
311 * \param srcPacking source image pixel packing
312 * \return resulting image with format = textureBaseFormat and type = GLfloat.
315 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
316 GLenum logicalBaseFormat
,
317 GLenum textureBaseFormat
,
318 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
319 GLenum srcFormat
, GLenum srcType
,
320 const GLvoid
*srcAddr
,
321 const struct gl_pixelstore_attrib
*srcPacking
,
322 GLbitfield transferOps
)
325 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
326 const GLint srcStride
=
327 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
331 ASSERT(dims
>= 1 && dims
<= 3);
333 ASSERT(logicalBaseFormat
== GL_RGBA
||
334 logicalBaseFormat
== GL_RGB
||
335 logicalBaseFormat
== GL_RG
||
336 logicalBaseFormat
== GL_RED
||
337 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
338 logicalBaseFormat
== GL_LUMINANCE
||
339 logicalBaseFormat
== GL_ALPHA
||
340 logicalBaseFormat
== GL_INTENSITY
||
341 logicalBaseFormat
== GL_COLOR_INDEX
||
342 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
344 ASSERT(textureBaseFormat
== GL_RGBA
||
345 textureBaseFormat
== GL_RGB
||
346 textureBaseFormat
== GL_RG
||
347 textureBaseFormat
== GL_RED
||
348 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
349 textureBaseFormat
== GL_LUMINANCE
||
350 textureBaseFormat
== GL_ALPHA
||
351 textureBaseFormat
== GL_INTENSITY
||
352 textureBaseFormat
== GL_COLOR_INDEX
||
353 textureBaseFormat
== GL_DEPTH_COMPONENT
);
355 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
356 * components
* sizeof(GLfloat
));
361 for (img
= 0; img
< srcDepth
; img
++) {
363 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
367 for (row
= 0; row
< srcHeight
; row
++) {
368 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
369 dst
, srcFormat
, srcType
, src
,
370 srcPacking
, transferOps
);
371 dst
+= srcWidth
* components
;
376 if (logicalBaseFormat
!= textureBaseFormat
) {
378 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
379 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
384 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
385 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
386 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
388 /* The actual texture format should have at least as many components
389 * as the logical texture format.
391 ASSERT(texComponents
>= logComponents
);
393 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
394 * texComponents
* sizeof(GLfloat
));
400 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
402 n
= srcWidth
* srcHeight
* srcDepth
;
403 for (i
= 0; i
< n
; i
++) {
405 for (k
= 0; k
< texComponents
; k
++) {
408 newImage
[i
* texComponents
+ k
] = 0.0F
;
410 newImage
[i
* texComponents
+ k
] = 1.0F
;
412 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
417 tempImage
= newImage
;
425 * Make temporary image with uint pixel values. Used for unsigned
426 * integer-valued textures.
429 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
430 GLenum logicalBaseFormat
,
431 GLenum textureBaseFormat
,
432 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
433 GLenum srcFormat
, GLenum srcType
,
434 const GLvoid
*srcAddr
,
435 const struct gl_pixelstore_attrib
*srcPacking
)
438 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
439 const GLint srcStride
=
440 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
444 ASSERT(dims
>= 1 && dims
<= 3);
446 ASSERT(logicalBaseFormat
== GL_RGBA
||
447 logicalBaseFormat
== GL_RGB
||
448 logicalBaseFormat
== GL_RG
||
449 logicalBaseFormat
== GL_RED
||
450 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
451 logicalBaseFormat
== GL_LUMINANCE
||
452 logicalBaseFormat
== GL_INTENSITY
||
453 logicalBaseFormat
== GL_ALPHA
);
455 ASSERT(textureBaseFormat
== GL_RGBA
||
456 textureBaseFormat
== GL_RGB
||
457 textureBaseFormat
== GL_RG
||
458 textureBaseFormat
== GL_RED
||
459 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
460 textureBaseFormat
== GL_LUMINANCE
||
461 textureBaseFormat
== GL_ALPHA
);
463 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
464 * components
* sizeof(GLuint
));
469 for (img
= 0; img
< srcDepth
; img
++) {
471 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
475 for (row
= 0; row
< srcHeight
; row
++) {
476 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
477 dst
, srcFormat
, srcType
, src
,
479 dst
+= srcWidth
* components
;
484 if (logicalBaseFormat
!= textureBaseFormat
) {
486 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
487 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
492 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
493 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
494 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
496 /* The actual texture format should have at least as many components
497 * as the logical texture format.
499 ASSERT(texComponents
>= logComponents
);
501 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
502 * texComponents
* sizeof(GLuint
));
508 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
510 n
= srcWidth
* srcHeight
* srcDepth
;
511 for (i
= 0; i
< n
; i
++) {
513 for (k
= 0; k
< texComponents
; k
++) {
516 newImage
[i
* texComponents
+ k
] = 0.0F
;
518 newImage
[i
* texComponents
+ k
] = 1.0F
;
520 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
525 tempImage
= newImage
;
534 * Make a temporary (color) texture image with GLchan components.
535 * Apply all needed pixel unpacking and pixel transfer operations.
536 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
537 * Suppose the user specifies GL_LUMINANCE as the internal texture format
538 * but the graphics hardware doesn't support luminance textures. So, we might
539 * use an RGB hardware format instead.
540 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
542 * \param ctx the rendering context
543 * \param dims image dimensions: 1, 2 or 3
544 * \param logicalBaseFormat basic texture derived from the user's
545 * internal texture format value
546 * \param textureBaseFormat the actual basic format of the texture
547 * \param srcWidth source image width
548 * \param srcHeight source image height
549 * \param srcDepth source image depth
550 * \param srcFormat source image format
551 * \param srcType source image type
552 * \param srcAddr source image address
553 * \param srcPacking source image pixel packing
554 * \return resulting image with format = textureBaseFormat and type = GLchan.
557 _mesa_make_temp_chan_image(struct gl_context
*ctx
, GLuint dims
,
558 GLenum logicalBaseFormat
,
559 GLenum textureBaseFormat
,
560 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
561 GLenum srcFormat
, GLenum srcType
,
562 const GLvoid
*srcAddr
,
563 const struct gl_pixelstore_attrib
*srcPacking
)
565 GLuint transferOps
= ctx
->_ImageTransferState
;
566 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
568 GLchan
*tempImage
, *dst
;
570 ASSERT(dims
>= 1 && dims
<= 3);
572 ASSERT(logicalBaseFormat
== GL_RGBA
||
573 logicalBaseFormat
== GL_RGB
||
574 logicalBaseFormat
== GL_RG
||
575 logicalBaseFormat
== GL_RED
||
576 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
577 logicalBaseFormat
== GL_LUMINANCE
||
578 logicalBaseFormat
== GL_ALPHA
||
579 logicalBaseFormat
== GL_INTENSITY
);
581 ASSERT(textureBaseFormat
== GL_RGBA
||
582 textureBaseFormat
== GL_RGB
||
583 textureBaseFormat
== GL_RG
||
584 textureBaseFormat
== GL_RED
||
585 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
586 textureBaseFormat
== GL_LUMINANCE
||
587 textureBaseFormat
== GL_ALPHA
||
588 textureBaseFormat
== GL_INTENSITY
);
590 /* unpack and transfer the source image */
591 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
592 * components
* sizeof(GLchan
));
598 for (img
= 0; img
< srcDepth
; img
++) {
599 const GLint srcStride
=
600 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
602 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
606 for (row
= 0; row
< srcHeight
; row
++) {
607 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
608 srcFormat
, srcType
, src
, srcPacking
,
610 dst
+= srcWidth
* components
;
615 if (logicalBaseFormat
!= textureBaseFormat
) {
616 /* one more conversion step */
617 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
618 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
623 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
624 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
625 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
627 /* The actual texture format should have at least as many components
628 * as the logical texture format.
630 ASSERT(texComponents
>= logComponents
);
632 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
633 * texComponents
* sizeof(GLchan
));
639 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
641 n
= srcWidth
* srcHeight
* srcDepth
;
642 for (i
= 0; i
< n
; i
++) {
644 for (k
= 0; k
< texComponents
; k
++) {
647 newImage
[i
* texComponents
+ k
] = 0;
649 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
651 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
656 tempImage
= newImage
;
664 * Copy GLubyte pixels from <src> to <dst> with swizzling.
665 * \param dst destination pixels
666 * \param dstComponents number of color components in destination pixels
667 * \param src source pixels
668 * \param srcComponents number of color components in source pixels
669 * \param map the swizzle mapping. map[X] says where to find the X component
670 * in the source image's pixels. For example, if the source image
671 * is GL_BGRA and X = red, map[0] yields 2.
672 * \param count number of pixels to copy/swizzle.
675 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
676 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
678 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
681 for (i = 0; i < count; i++) { \
683 if (srcComps == 4) { \
684 COPY_4UBV(tmp, src); \
687 for (j = 0; j < srcComps; j++) { \
692 for (j = 0; j < dstComps; j++) { \
693 dst[j] = tmp[map[j]]; \
704 ASSERT(srcComponents
<= 4);
705 ASSERT(dstComponents
<= 4);
707 switch (dstComponents
) {
709 switch (srcComponents
) {
711 SWZ_CPY(dst
, src
, count
, 4, 4);
714 SWZ_CPY(dst
, src
, count
, 4, 3);
717 SWZ_CPY(dst
, src
, count
, 4, 2);
720 SWZ_CPY(dst
, src
, count
, 4, 1);
727 switch (srcComponents
) {
729 SWZ_CPY(dst
, src
, count
, 3, 4);
732 SWZ_CPY(dst
, src
, count
, 3, 3);
735 SWZ_CPY(dst
, src
, count
, 3, 2);
738 SWZ_CPY(dst
, src
, count
, 3, 1);
745 switch (srcComponents
) {
747 SWZ_CPY(dst
, src
, count
, 2, 4);
750 SWZ_CPY(dst
, src
, count
, 2, 3);
753 SWZ_CPY(dst
, src
, count
, 2, 2);
756 SWZ_CPY(dst
, src
, count
, 2, 1);
763 switch (srcComponents
) {
765 SWZ_CPY(dst
, src
, count
, 1, 4);
768 SWZ_CPY(dst
, src
, count
, 1, 3);
771 SWZ_CPY(dst
, src
, count
, 1, 2);
774 SWZ_CPY(dst
, src
, count
, 1, 1);
788 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
789 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
793 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
794 * mapping array depending on endianness.
796 static const GLubyte
*
797 type_mapping( GLenum srcType
)
801 case GL_UNSIGNED_BYTE
:
803 case GL_UNSIGNED_INT_8_8_8_8
:
804 return _mesa_little_endian() ? map_3210
: map_identity
;
805 case GL_UNSIGNED_INT_8_8_8_8_REV
:
806 return _mesa_little_endian() ? map_identity
: map_3210
;
814 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
815 * mapping array depending on pixelstore byte swapping state.
817 static const GLubyte
*
818 byteswap_mapping( GLboolean swapBytes
,
826 case GL_UNSIGNED_BYTE
:
828 case GL_UNSIGNED_INT_8_8_8_8
:
829 case GL_UNSIGNED_INT_8_8_8_8_REV
:
839 * Transfer a GLubyte texture image with component swizzling.
842 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
847 GLenum baseInternalFormat
,
849 const GLubyte
*rgba2dst
,
850 GLuint dstComponents
,
853 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
855 const GLuint
*dstImageOffsets
,
857 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
858 const GLvoid
*srcAddr
,
859 const struct gl_pixelstore_attrib
*srcPacking
)
861 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
862 const GLubyte
*srctype2ubyte
, *swap
;
863 GLubyte map
[4], src2base
[6], base2rgba
[6];
865 const GLint srcRowStride
=
866 _mesa_image_row_stride(srcPacking
, srcWidth
,
867 srcFormat
, GL_UNSIGNED_BYTE
);
868 const GLint srcImageStride
869 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
871 const GLubyte
*srcImage
872 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
873 srcWidth
, srcHeight
, srcFormat
,
874 GL_UNSIGNED_BYTE
, 0, 0, 0);
878 /* Translate from src->baseInternal->GL_RGBA->dst. This will
879 * correctly deal with RGBA->RGB->RGBA conversions where the final
880 * A value must be 0xff regardless of the incoming alpha values.
882 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
883 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
884 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
885 srctype2ubyte
= type_mapping(srcType
);
888 for (i
= 0; i
< 4; i
++)
889 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
891 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
893 if (srcComponents
== dstComponents
&&
894 srcRowStride
== dstRowStride
&&
895 srcRowStride
== srcWidth
* srcComponents
&&
897 /* 1 and 2D images only */
898 GLubyte
*dstImage
= (GLubyte
*) dstAddr
899 + dstYoffset
* dstRowStride
900 + dstXoffset
* dstComponents
;
901 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
902 srcWidth
* srcHeight
);
906 for (img
= 0; img
< srcDepth
; img
++) {
907 const GLubyte
*srcRow
= srcImage
;
908 GLubyte
*dstRow
= (GLubyte
*) dstAddr
909 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
910 + dstYoffset
* dstRowStride
911 + dstXoffset
* dstComponents
;
912 for (row
= 0; row
< srcHeight
; row
++) {
913 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
914 dstRow
+= dstRowStride
;
915 srcRow
+= srcRowStride
;
917 srcImage
+= srcImageStride
;
924 * Teximage storage routine for when a simple memcpy will do.
925 * No pixel transfer operations or special texel encodings allowed.
926 * 1D, 2D and 3D images supported.
929 memcpy_texture(struct gl_context
*ctx
,
933 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
935 const GLuint
*dstImageOffsets
,
936 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
937 GLenum srcFormat
, GLenum srcType
,
938 const GLvoid
*srcAddr
,
939 const struct gl_pixelstore_attrib
*srcPacking
)
941 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
943 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
944 srcWidth
, srcHeight
, srcFormat
, srcType
);
945 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
946 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
947 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
948 const GLint bytesPerRow
= srcWidth
* texelBytes
;
951 /* XXX update/re-enable for dstImageOffsets array */
952 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
953 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
954 GLubyte
*dstImage
= (GLubyte
*) dstAddr
955 + dstZoffset
* dstImageStride
956 + dstYoffset
* dstRowStride
957 + dstXoffset
* texelBytes
;
959 if (dstRowStride
== srcRowStride
&&
960 dstRowStride
== bytesPerRow
&&
961 ((dstImageStride
== srcImageStride
&&
962 dstImageStride
== bytesPerImage
) ||
965 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
970 for (img
= 0; img
< srcDepth
; img
++) {
971 const GLubyte
*srcRow
= srcImage
;
972 GLubyte
*dstRow
= dstImage
;
973 for (row
= 0; row
< srcHeight
; row
++) {
974 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
975 dstRow
+= dstRowStride
;
976 srcRow
+= srcRowStride
;
978 srcImage
+= srcImageStride
;
979 dstImage
+= dstImageStride
;
985 for (img
= 0; img
< srcDepth
; img
++) {
986 const GLubyte
*srcRow
= srcImage
;
987 GLubyte
*dstRow
= (GLubyte
*) dstAddr
988 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
989 + dstYoffset
* dstRowStride
990 + dstXoffset
* texelBytes
;
991 for (row
= 0; row
< srcHeight
; row
++) {
992 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
993 dstRow
+= dstRowStride
;
994 srcRow
+= srcRowStride
;
996 srcImage
+= srcImageStride
;
1003 * Store a 32-bit integer depth component texture image.
1006 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1008 const GLuint depthScale
= 0xffffffff;
1009 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1011 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1012 ASSERT(texelBytes
== sizeof(GLuint
));
1014 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1015 ctx
->Pixel
.DepthBias
== 0.0f
&&
1016 !srcPacking
->SwapBytes
&&
1017 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1018 srcFormat
== GL_DEPTH_COMPONENT
&&
1019 srcType
== GL_UNSIGNED_INT
) {
1020 /* simple memcpy path */
1021 memcpy_texture(ctx
, dims
,
1022 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1025 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1026 srcAddr
, srcPacking
);
1031 for (img
= 0; img
< srcDepth
; img
++) {
1032 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1033 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1034 + dstYoffset
* dstRowStride
1035 + dstXoffset
* texelBytes
;
1036 for (row
= 0; row
< srcHeight
; row
++) {
1037 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1038 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1039 _mesa_unpack_depth_span(ctx
, srcWidth
,
1040 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1041 depthScale
, srcType
, src
, srcPacking
);
1042 dstRow
+= dstRowStride
;
1051 * Store a 24-bit integer depth component texture image.
1054 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1056 const GLuint depthScale
= 0xffffff;
1057 const GLuint texelBytes
= 4;
1060 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1065 for (img
= 0; img
< srcDepth
; img
++) {
1066 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1067 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1068 + dstYoffset
* dstRowStride
1069 + dstXoffset
* texelBytes
;
1070 for (row
= 0; row
< srcHeight
; row
++) {
1071 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1072 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1073 _mesa_unpack_depth_span(ctx
, srcWidth
,
1074 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1075 depthScale
, srcType
, src
, srcPacking
);
1076 dstRow
+= dstRowStride
;
1085 * Store a 24-bit integer depth component texture image.
1088 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1090 const GLuint depthScale
= 0xffffff;
1091 const GLuint texelBytes
= 4;
1094 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1099 for (img
= 0; img
< srcDepth
; img
++) {
1100 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1101 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1102 + dstYoffset
* dstRowStride
1103 + dstXoffset
* texelBytes
;
1104 for (row
= 0; row
< srcHeight
; row
++) {
1105 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1106 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1107 GLuint
*dst
= (GLuint
*) dstRow
;
1109 _mesa_unpack_depth_span(ctx
, srcWidth
,
1110 GL_UNSIGNED_INT
, dst
,
1111 depthScale
, srcType
, src
, srcPacking
);
1112 for (i
= 0; i
< srcWidth
; i
++)
1114 dstRow
+= dstRowStride
;
1123 * Store a 16-bit integer depth component texture image.
1126 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1128 const GLuint depthScale
= 0xffff;
1129 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1131 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1132 ASSERT(texelBytes
== sizeof(GLushort
));
1134 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1135 ctx
->Pixel
.DepthBias
== 0.0f
&&
1136 !srcPacking
->SwapBytes
&&
1137 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1138 srcFormat
== GL_DEPTH_COMPONENT
&&
1139 srcType
== GL_UNSIGNED_SHORT
) {
1140 /* simple memcpy path */
1141 memcpy_texture(ctx
, dims
,
1142 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1145 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1146 srcAddr
, srcPacking
);
1151 for (img
= 0; img
< srcDepth
; img
++) {
1152 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1153 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1154 + dstYoffset
* dstRowStride
1155 + dstXoffset
* texelBytes
;
1156 for (row
= 0; row
< srcHeight
; row
++) {
1157 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1158 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1159 GLushort
*dst16
= (GLushort
*) dstRow
;
1160 _mesa_unpack_depth_span(ctx
, srcWidth
,
1161 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1162 srcType
, src
, srcPacking
);
1163 dstRow
+= dstRowStride
;
1172 * Store an rgb565 or rgb565_rev texture image.
1175 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1177 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1178 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1180 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1181 dstFormat
== MESA_FORMAT_RGB565_REV
);
1182 ASSERT(texelBytes
== 2);
1184 if (!ctx
->_ImageTransferState
&&
1185 !srcPacking
->SwapBytes
&&
1186 dstFormat
== MESA_FORMAT_RGB565
&&
1187 baseInternalFormat
== GL_RGB
&&
1188 srcFormat
== GL_RGB
&&
1189 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1190 /* simple memcpy path */
1191 memcpy_texture(ctx
, dims
,
1192 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1195 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1196 srcAddr
, srcPacking
);
1198 else if (!ctx
->_ImageTransferState
&&
1199 !srcPacking
->SwapBytes
&&
1200 baseInternalFormat
== GL_RGB
&&
1201 srcFormat
== GL_RGB
&&
1202 srcType
== GL_UNSIGNED_BYTE
&&
1204 /* do optimized tex store */
1205 const GLint srcRowStride
=
1206 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1207 const GLubyte
*src
= (const GLubyte
*)
1208 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1209 srcFormat
, srcType
, 0, 0, 0);
1210 GLubyte
*dst
= (GLubyte
*) dstAddr
1211 + dstYoffset
* dstRowStride
1212 + dstXoffset
* texelBytes
;
1214 for (row
= 0; row
< srcHeight
; row
++) {
1215 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1216 GLushort
*dstUS
= (GLushort
*) dst
;
1217 /* check for byteswapped format */
1218 if (dstFormat
== MESA_FORMAT_RGB565
) {
1219 for (col
= 0; col
< srcWidth
; col
++) {
1220 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1225 for (col
= 0; col
< srcWidth
; col
++) {
1226 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1230 dst
+= dstRowStride
;
1231 src
+= srcRowStride
;
1236 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1239 srcWidth
, srcHeight
, srcDepth
,
1240 srcFormat
, srcType
, srcAddr
,
1242 const GLchan
*src
= tempImage
;
1243 GLint img
, row
, col
;
1246 for (img
= 0; img
< srcDepth
; img
++) {
1247 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1248 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1249 + dstYoffset
* dstRowStride
1250 + dstXoffset
* texelBytes
;
1251 for (row
= 0; row
< srcHeight
; row
++) {
1252 GLushort
*dstUS
= (GLushort
*) dstRow
;
1253 /* check for byteswapped format */
1254 if (dstFormat
== MESA_FORMAT_RGB565
) {
1255 for (col
= 0; col
< srcWidth
; col
++) {
1256 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1257 CHAN_TO_UBYTE(src
[GCOMP
]),
1258 CHAN_TO_UBYTE(src
[BCOMP
]) );
1263 for (col
= 0; col
< srcWidth
; col
++) {
1264 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1265 CHAN_TO_UBYTE(src
[GCOMP
]),
1266 CHAN_TO_UBYTE(src
[BCOMP
]) );
1270 dstRow
+= dstRowStride
;
1273 free((void *) tempImage
);
1280 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1283 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1285 const GLboolean littleEndian
= _mesa_little_endian();
1286 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1287 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1289 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1290 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1291 ASSERT(texelBytes
== 4);
1293 if (!ctx
->_ImageTransferState
&&
1294 !srcPacking
->SwapBytes
&&
1295 dstFormat
== MESA_FORMAT_RGBA8888
&&
1296 baseInternalFormat
== GL_RGBA
&&
1297 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1298 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1299 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1300 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1301 /* simple memcpy path */
1302 memcpy_texture(ctx
, dims
,
1303 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1306 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1307 srcAddr
, srcPacking
);
1309 else if (!ctx
->_ImageTransferState
&&
1310 !srcPacking
->SwapBytes
&&
1311 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1312 baseInternalFormat
== GL_RGBA
&&
1313 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1314 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1315 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1316 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1317 /* simple memcpy path */
1318 memcpy_texture(ctx
, dims
,
1319 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1322 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1323 srcAddr
, srcPacking
);
1325 else if (!ctx
->_ImageTransferState
&&
1326 (srcType
== GL_UNSIGNED_BYTE
||
1327 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1328 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1329 can_swizzle(baseInternalFormat
) &&
1330 can_swizzle(srcFormat
)) {
1334 /* dstmap - how to swizzle from RGBA to dst format:
1336 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1337 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1350 _mesa_swizzle_ubyte_image(ctx
, dims
,
1355 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1356 dstRowStride
, dstImageOffsets
,
1357 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1362 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1365 srcWidth
, srcHeight
, srcDepth
,
1366 srcFormat
, srcType
, srcAddr
,
1368 const GLchan
*src
= tempImage
;
1369 GLint img
, row
, col
;
1372 for (img
= 0; img
< srcDepth
; img
++) {
1373 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1374 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1375 + dstYoffset
* dstRowStride
1376 + dstXoffset
* texelBytes
;
1377 for (row
= 0; row
< srcHeight
; row
++) {
1378 GLuint
*dstUI
= (GLuint
*) dstRow
;
1379 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1380 for (col
= 0; col
< srcWidth
; col
++) {
1381 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1382 CHAN_TO_UBYTE(src
[GCOMP
]),
1383 CHAN_TO_UBYTE(src
[BCOMP
]),
1384 CHAN_TO_UBYTE(src
[ACOMP
]) );
1389 for (col
= 0; col
< srcWidth
; col
++) {
1390 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1391 CHAN_TO_UBYTE(src
[GCOMP
]),
1392 CHAN_TO_UBYTE(src
[BCOMP
]),
1393 CHAN_TO_UBYTE(src
[ACOMP
]) );
1397 dstRow
+= dstRowStride
;
1400 free((void *) tempImage
);
1407 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1409 const GLboolean littleEndian
= _mesa_little_endian();
1410 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1411 const GLenum baseFormat
= GL_RGBA
;
1413 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1414 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1415 dstFormat
== MESA_FORMAT_XRGB8888
||
1416 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1417 ASSERT(texelBytes
== 4);
1419 if (!ctx
->_ImageTransferState
&&
1420 !srcPacking
->SwapBytes
&&
1421 (dstFormat
== MESA_FORMAT_ARGB8888
||
1422 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1423 baseInternalFormat
== GL_RGBA
&&
1424 srcFormat
== GL_BGRA
&&
1425 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1426 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1427 /* simple memcpy path (little endian) */
1428 memcpy_texture(ctx
, dims
,
1429 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1432 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1433 srcAddr
, srcPacking
);
1435 else if (!ctx
->_ImageTransferState
&&
1436 !srcPacking
->SwapBytes
&&
1437 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1438 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1439 baseInternalFormat
== GL_RGBA
&&
1440 srcFormat
== GL_BGRA
&&
1441 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1442 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1443 /* simple memcpy path (big endian) */
1444 memcpy_texture(ctx
, dims
,
1445 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1448 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1449 srcAddr
, srcPacking
);
1451 else if (!ctx
->_ImageTransferState
&&
1452 !srcPacking
->SwapBytes
&&
1453 (dstFormat
== MESA_FORMAT_ARGB8888
||
1454 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1455 srcFormat
== GL_RGB
&&
1456 (baseInternalFormat
== GL_RGBA
||
1457 baseInternalFormat
== GL_RGB
) &&
1458 srcType
== GL_UNSIGNED_BYTE
) {
1460 for (img
= 0; img
< srcDepth
; img
++) {
1461 const GLint srcRowStride
=
1462 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1463 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1464 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1465 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1466 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1467 + dstYoffset
* dstRowStride
1468 + dstXoffset
* texelBytes
;
1469 for (row
= 0; row
< srcHeight
; row
++) {
1470 GLuint
*d4
= (GLuint
*) dstRow
;
1471 for (col
= 0; col
< srcWidth
; col
++) {
1472 d4
[col
] = PACK_COLOR_8888(0xff,
1473 srcRow
[col
* 3 + RCOMP
],
1474 srcRow
[col
* 3 + GCOMP
],
1475 srcRow
[col
* 3 + BCOMP
]);
1477 dstRow
+= dstRowStride
;
1478 srcRow
+= srcRowStride
;
1482 else if (!ctx
->_ImageTransferState
&&
1483 !srcPacking
->SwapBytes
&&
1484 dstFormat
== MESA_FORMAT_ARGB8888
&&
1485 srcFormat
== GL_RGBA
&&
1486 baseInternalFormat
== GL_RGBA
&&
1487 srcType
== GL_UNSIGNED_BYTE
) {
1488 /* same as above case, but src data has alpha too */
1489 GLint img
, row
, col
;
1490 /* For some reason, streaming copies to write-combined regions
1491 * are extremely sensitive to the characteristics of how the
1492 * source data is retrieved. By reordering the source reads to
1493 * be in-order, the speed of this operation increases by half.
1494 * Strangely the same isn't required for the RGB path, above.
1496 for (img
= 0; img
< srcDepth
; img
++) {
1497 const GLint srcRowStride
=
1498 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1499 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1500 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1501 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1502 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1503 + dstYoffset
* dstRowStride
1504 + dstXoffset
* texelBytes
;
1505 for (row
= 0; row
< srcHeight
; row
++) {
1506 GLuint
*d4
= (GLuint
*) dstRow
;
1507 for (col
= 0; col
< srcWidth
; col
++) {
1508 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1509 srcRow
[col
* 4 + RCOMP
],
1510 srcRow
[col
* 4 + GCOMP
],
1511 srcRow
[col
* 4 + BCOMP
]);
1513 dstRow
+= dstRowStride
;
1514 srcRow
+= srcRowStride
;
1518 else if (!ctx
->_ImageTransferState
&&
1519 (srcType
== GL_UNSIGNED_BYTE
||
1520 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1521 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1522 can_swizzle(baseInternalFormat
) &&
1523 can_swizzle(srcFormat
)) {
1527 /* dstmap - how to swizzle from RGBA to dst format:
1529 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1530 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1531 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1532 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1533 dstmap
[3] = 3; /* alpha */
1534 dstmap
[2] = 0; /* red */
1535 dstmap
[1] = 1; /* green */
1536 dstmap
[0] = 2; /* blue */
1539 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1540 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1541 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1542 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1549 _mesa_swizzle_ubyte_image(ctx
, dims
,
1554 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1557 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1562 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1565 srcWidth
, srcHeight
, srcDepth
,
1566 srcFormat
, srcType
, srcAddr
,
1568 const GLchan
*src
= tempImage
;
1569 GLint img
, row
, col
;
1572 for (img
= 0; img
< srcDepth
; img
++) {
1573 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1574 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1575 + dstYoffset
* dstRowStride
1576 + dstXoffset
* texelBytes
;
1577 for (row
= 0; row
< srcHeight
; row
++) {
1578 GLuint
*dstUI
= (GLuint
*) dstRow
;
1579 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1580 for (col
= 0; col
< srcWidth
; col
++) {
1581 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1582 CHAN_TO_UBYTE(src
[RCOMP
]),
1583 CHAN_TO_UBYTE(src
[GCOMP
]),
1584 CHAN_TO_UBYTE(src
[BCOMP
]) );
1588 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1589 for (col
= 0; col
< srcWidth
; col
++) {
1590 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1591 CHAN_TO_UBYTE(src
[RCOMP
]),
1592 CHAN_TO_UBYTE(src
[GCOMP
]),
1593 CHAN_TO_UBYTE(src
[BCOMP
]) );
1598 for (col
= 0; col
< srcWidth
; col
++) {
1599 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1600 CHAN_TO_UBYTE(src
[RCOMP
]),
1601 CHAN_TO_UBYTE(src
[GCOMP
]),
1602 CHAN_TO_UBYTE(src
[BCOMP
]) );
1606 dstRow
+= dstRowStride
;
1609 free((void *) tempImage
);
1616 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1618 const GLboolean littleEndian
= _mesa_little_endian();
1619 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1620 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1622 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1623 ASSERT(texelBytes
== 3);
1625 if (!ctx
->_ImageTransferState
&&
1626 !srcPacking
->SwapBytes
&&
1627 baseInternalFormat
== GL_RGB
&&
1628 srcFormat
== GL_BGR
&&
1629 srcType
== GL_UNSIGNED_BYTE
&&
1631 /* simple memcpy path */
1632 memcpy_texture(ctx
, dims
,
1633 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1636 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1637 srcAddr
, srcPacking
);
1639 else if (!ctx
->_ImageTransferState
&&
1640 !srcPacking
->SwapBytes
&&
1641 srcFormat
== GL_RGBA
&&
1642 srcType
== GL_UNSIGNED_BYTE
) {
1643 /* extract RGB from RGBA */
1644 GLint img
, row
, col
;
1645 for (img
= 0; img
< srcDepth
; img
++) {
1646 const GLint srcRowStride
=
1647 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1648 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1649 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1650 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1651 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1652 + dstYoffset
* dstRowStride
1653 + dstXoffset
* texelBytes
;
1654 for (row
= 0; row
< srcHeight
; row
++) {
1655 for (col
= 0; col
< srcWidth
; col
++) {
1656 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1657 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1658 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1660 dstRow
+= dstRowStride
;
1661 srcRow
+= srcRowStride
;
1665 else if (!ctx
->_ImageTransferState
&&
1666 srcType
== GL_UNSIGNED_BYTE
&&
1667 can_swizzle(baseInternalFormat
) &&
1668 can_swizzle(srcFormat
)) {
1672 /* dstmap - how to swizzle from RGBA to dst format:
1677 dstmap
[3] = ONE
; /* ? */
1679 _mesa_swizzle_ubyte_image(ctx
, dims
,
1684 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1685 dstRowStride
, dstImageOffsets
,
1686 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1691 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1694 srcWidth
, srcHeight
, srcDepth
,
1695 srcFormat
, srcType
, srcAddr
,
1697 const GLchan
*src
= (const GLchan
*) tempImage
;
1698 GLint img
, row
, col
;
1701 for (img
= 0; img
< srcDepth
; img
++) {
1702 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1703 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1704 + dstYoffset
* dstRowStride
1705 + dstXoffset
* texelBytes
;
1706 for (row
= 0; row
< srcHeight
; row
++) {
1709 for (col
= 0; col
< srcWidth
; col
++) {
1710 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1711 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1712 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1717 for (col
= 0; col
< srcWidth
; col
++) {
1718 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1719 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1720 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1725 for (col
= 0; col
< srcWidth
; col
++) {
1726 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1727 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1728 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1732 dstRow
+= dstRowStride
;
1735 free((void *) tempImage
);
1742 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1744 const GLboolean littleEndian
= _mesa_little_endian();
1745 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1746 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1748 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1749 ASSERT(texelBytes
== 3);
1751 if (!ctx
->_ImageTransferState
&&
1752 !srcPacking
->SwapBytes
&&
1753 baseInternalFormat
== GL_RGB
&&
1754 srcFormat
== GL_RGB
&&
1755 srcType
== GL_UNSIGNED_BYTE
&&
1757 /* simple memcpy path */
1758 memcpy_texture(ctx
, dims
,
1759 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1762 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1763 srcAddr
, srcPacking
);
1765 else if (!ctx
->_ImageTransferState
&&
1766 !srcPacking
->SwapBytes
&&
1767 srcFormat
== GL_RGBA
&&
1768 srcType
== GL_UNSIGNED_BYTE
) {
1769 /* extract BGR from RGBA */
1771 for (img
= 0; img
< srcDepth
; img
++) {
1772 const GLint srcRowStride
=
1773 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1774 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1775 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1776 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1777 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1778 + dstYoffset
* dstRowStride
1779 + dstXoffset
* texelBytes
;
1780 for (row
= 0; row
< srcHeight
; row
++) {
1781 for (col
= 0; col
< srcWidth
; col
++) {
1782 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1783 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1784 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1786 dstRow
+= dstRowStride
;
1787 srcRow
+= srcRowStride
;
1791 else if (!ctx
->_ImageTransferState
&&
1792 srcType
== GL_UNSIGNED_BYTE
&&
1793 can_swizzle(baseInternalFormat
) &&
1794 can_swizzle(srcFormat
)) {
1798 /* dstmap - how to swizzle from RGBA to dst format:
1803 dstmap
[3] = ONE
; /* ? */
1805 _mesa_swizzle_ubyte_image(ctx
, dims
,
1810 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1811 dstRowStride
, dstImageOffsets
,
1812 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1817 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1820 srcWidth
, srcHeight
, srcDepth
,
1821 srcFormat
, srcType
, srcAddr
,
1823 const GLchan
*src
= (const GLchan
*) tempImage
;
1824 GLint img
, row
, col
;
1827 for (img
= 0; img
< srcDepth
; img
++) {
1828 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1829 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1830 + dstYoffset
* dstRowStride
1831 + dstXoffset
* texelBytes
;
1832 for (row
= 0; row
< srcHeight
; row
++) {
1833 for (col
= 0; col
< srcWidth
; col
++) {
1834 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1835 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1836 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1839 dstRow
+= dstRowStride
;
1842 free((void *) tempImage
);
1849 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1851 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1852 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1854 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1855 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1856 ASSERT(texelBytes
== 2);
1858 if (!ctx
->_ImageTransferState
&&
1859 !srcPacking
->SwapBytes
&&
1860 dstFormat
== MESA_FORMAT_ARGB4444
&&
1861 baseInternalFormat
== GL_RGBA
&&
1862 srcFormat
== GL_BGRA
&&
1863 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1864 /* simple memcpy path */
1865 memcpy_texture(ctx
, dims
,
1866 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1869 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1870 srcAddr
, srcPacking
);
1874 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1877 srcWidth
, srcHeight
, srcDepth
,
1878 srcFormat
, srcType
, srcAddr
,
1880 const GLchan
*src
= tempImage
;
1881 GLint img
, row
, col
;
1884 for (img
= 0; img
< srcDepth
; img
++) {
1885 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1886 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1887 + dstYoffset
* dstRowStride
1888 + dstXoffset
* texelBytes
;
1889 for (row
= 0; row
< srcHeight
; row
++) {
1890 GLushort
*dstUS
= (GLushort
*) dstRow
;
1891 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1892 for (col
= 0; col
< srcWidth
; col
++) {
1893 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1894 CHAN_TO_UBYTE(src
[RCOMP
]),
1895 CHAN_TO_UBYTE(src
[GCOMP
]),
1896 CHAN_TO_UBYTE(src
[BCOMP
]) );
1901 for (col
= 0; col
< srcWidth
; col
++) {
1902 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1903 CHAN_TO_UBYTE(src
[RCOMP
]),
1904 CHAN_TO_UBYTE(src
[GCOMP
]),
1905 CHAN_TO_UBYTE(src
[BCOMP
]) );
1909 dstRow
+= dstRowStride
;
1912 free((void *) tempImage
);
1918 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1920 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1921 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1923 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1924 ASSERT(texelBytes
== 2);
1926 if (!ctx
->_ImageTransferState
&&
1927 !srcPacking
->SwapBytes
&&
1928 dstFormat
== MESA_FORMAT_RGBA5551
&&
1929 baseInternalFormat
== GL_RGBA
&&
1930 srcFormat
== GL_RGBA
&&
1931 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1932 /* simple memcpy path */
1933 memcpy_texture(ctx
, dims
,
1934 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1937 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1938 srcAddr
, srcPacking
);
1942 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1945 srcWidth
, srcHeight
, srcDepth
,
1946 srcFormat
, srcType
, srcAddr
,
1948 const GLchan
*src
=tempImage
;
1949 GLint img
, row
, col
;
1952 for (img
= 0; img
< srcDepth
; img
++) {
1953 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1954 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1955 + dstYoffset
* dstRowStride
1956 + dstXoffset
* texelBytes
;
1957 for (row
= 0; row
< srcHeight
; row
++) {
1958 GLushort
*dstUS
= (GLushort
*) dstRow
;
1959 for (col
= 0; col
< srcWidth
; col
++) {
1960 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1961 CHAN_TO_UBYTE(src
[GCOMP
]),
1962 CHAN_TO_UBYTE(src
[BCOMP
]),
1963 CHAN_TO_UBYTE(src
[ACOMP
]) );
1966 dstRow
+= dstRowStride
;
1969 free((void *) tempImage
);
1975 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1977 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1978 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1980 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1981 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1982 ASSERT(texelBytes
== 2);
1984 if (!ctx
->_ImageTransferState
&&
1985 !srcPacking
->SwapBytes
&&
1986 dstFormat
== MESA_FORMAT_ARGB1555
&&
1987 baseInternalFormat
== GL_RGBA
&&
1988 srcFormat
== GL_BGRA
&&
1989 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1990 /* simple memcpy path */
1991 memcpy_texture(ctx
, dims
,
1992 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1995 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1996 srcAddr
, srcPacking
);
2000 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2003 srcWidth
, srcHeight
, srcDepth
,
2004 srcFormat
, srcType
, srcAddr
,
2006 const GLchan
*src
=tempImage
;
2007 GLint img
, row
, col
;
2010 for (img
= 0; img
< srcDepth
; img
++) {
2011 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2012 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2013 + dstYoffset
* dstRowStride
2014 + dstXoffset
* texelBytes
;
2015 for (row
= 0; row
< srcHeight
; row
++) {
2016 GLushort
*dstUS
= (GLushort
*) dstRow
;
2017 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2018 for (col
= 0; col
< srcWidth
; col
++) {
2019 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
2020 CHAN_TO_UBYTE(src
[RCOMP
]),
2021 CHAN_TO_UBYTE(src
[GCOMP
]),
2022 CHAN_TO_UBYTE(src
[BCOMP
]) );
2027 for (col
= 0; col
< srcWidth
; col
++) {
2028 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2029 CHAN_TO_UBYTE(src
[RCOMP
]),
2030 CHAN_TO_UBYTE(src
[GCOMP
]),
2031 CHAN_TO_UBYTE(src
[BCOMP
]) );
2035 dstRow
+= dstRowStride
;
2038 free((void *) tempImage
);
2045 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2047 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2048 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2050 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2051 ASSERT(texelBytes
== 4);
2053 if (!ctx
->_ImageTransferState
&&
2054 !srcPacking
->SwapBytes
&&
2055 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2056 srcFormat
== GL_BGRA
&&
2057 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2058 baseInternalFormat
== GL_RGBA
) {
2059 /* simple memcpy path */
2060 memcpy_texture(ctx
, dims
,
2061 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2064 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2065 srcAddr
, srcPacking
);
2069 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2072 srcWidth
, srcHeight
, srcDepth
,
2073 srcFormat
, srcType
, srcAddr
,
2075 ctx
->_ImageTransferState
);
2076 const GLfloat
*src
= tempImage
;
2077 GLint img
, row
, col
;
2080 for (img
= 0; img
< srcDepth
; img
++) {
2081 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2082 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2083 + dstYoffset
* dstRowStride
2084 + dstXoffset
* texelBytes
;
2085 if (baseInternalFormat
== GL_RGBA
) {
2086 for (row
= 0; row
< srcHeight
; row
++) {
2087 GLuint
*dstUI
= (GLuint
*) dstRow
;
2088 for (col
= 0; col
< srcWidth
; col
++) {
2091 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2092 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2093 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2094 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2095 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2098 dstRow
+= dstRowStride
;
2100 } else if (baseInternalFormat
== GL_RGB
) {
2101 for (row
= 0; row
< srcHeight
; row
++) {
2102 GLuint
*dstUI
= (GLuint
*) dstRow
;
2103 for (col
= 0; col
< srcWidth
; col
++) {
2106 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2107 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2108 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2109 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2112 dstRow
+= dstRowStride
;
2118 free((void *) tempImage
);
2125 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2128 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2130 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2131 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2133 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2134 ASSERT(texelBytes
== 1);
2138 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2141 srcWidth
, srcHeight
, srcDepth
,
2142 srcFormat
, srcType
, srcAddr
,
2144 const GLchan
*src
= tempImage
;
2145 GLint img
, row
, col
;
2148 for (img
= 0; img
< srcDepth
; img
++) {
2149 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2150 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2151 + dstYoffset
* dstRowStride
2152 + dstXoffset
* texelBytes
;
2153 for (row
= 0; row
< srcHeight
; row
++) {
2154 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2155 for (col
= 0; col
< srcWidth
; col
++) {
2156 /* src[0] is luminance, src[1] is alpha */
2157 dstUS
[col
] = PACK_COLOR_44( CHAN_TO_UBYTE(src
[1]),
2158 CHAN_TO_UBYTE(src
[0]) );
2161 dstRow
+= dstRowStride
;
2164 free((void *) tempImage
);
2171 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2174 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2176 const GLboolean littleEndian
= _mesa_little_endian();
2177 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2178 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2180 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2181 dstFormat
== MESA_FORMAT_AL88_REV
||
2182 dstFormat
== MESA_FORMAT_RG88
||
2183 dstFormat
== MESA_FORMAT_RG88_REV
);
2184 ASSERT(texelBytes
== 2);
2186 if (!ctx
->_ImageTransferState
&&
2187 !srcPacking
->SwapBytes
&&
2188 ((dstFormat
== MESA_FORMAT_AL88
&&
2189 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2190 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2191 (dstFormat
== MESA_FORMAT_RG88
&&
2192 baseInternalFormat
== srcFormat
)) &&
2193 srcType
== GL_UNSIGNED_BYTE
&&
2195 /* simple memcpy path */
2196 memcpy_texture(ctx
, dims
,
2197 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2200 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2201 srcAddr
, srcPacking
);
2203 else if (!ctx
->_ImageTransferState
&&
2205 srcType
== GL_UNSIGNED_BYTE
&&
2206 can_swizzle(baseInternalFormat
) &&
2207 can_swizzle(srcFormat
)) {
2210 /* dstmap - how to swizzle from RGBA to dst format:
2212 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2213 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2214 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2224 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2225 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2234 dstmap
[2] = ZERO
; /* ? */
2235 dstmap
[3] = ONE
; /* ? */
2237 _mesa_swizzle_ubyte_image(ctx
, dims
,
2242 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2243 dstRowStride
, dstImageOffsets
,
2244 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2249 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2252 srcWidth
, srcHeight
, srcDepth
,
2253 srcFormat
, srcType
, srcAddr
,
2255 const GLchan
*src
= tempImage
;
2256 GLint img
, row
, col
;
2259 for (img
= 0; img
< srcDepth
; img
++) {
2260 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2261 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2262 + dstYoffset
* dstRowStride
2263 + dstXoffset
* texelBytes
;
2264 for (row
= 0; row
< srcHeight
; row
++) {
2265 GLushort
*dstUS
= (GLushort
*) dstRow
;
2266 if (dstFormat
== MESA_FORMAT_AL88
||
2267 dstFormat
== MESA_FORMAT_RG88
) {
2268 for (col
= 0; col
< srcWidth
; col
++) {
2269 /* src[0] is luminance, src[1] is alpha */
2270 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2271 CHAN_TO_UBYTE(src
[0]) );
2276 for (col
= 0; col
< srcWidth
; col
++) {
2277 /* src[0] is luminance, src[1] is alpha */
2278 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2279 CHAN_TO_UBYTE(src
[0]) );
2283 dstRow
+= dstRowStride
;
2286 free((void *) tempImage
);
2293 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2296 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2298 const GLboolean littleEndian
= _mesa_little_endian();
2299 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2300 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2302 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2303 dstFormat
== MESA_FORMAT_AL1616_REV
||
2304 dstFormat
== MESA_FORMAT_RG1616
||
2305 dstFormat
== MESA_FORMAT_RG1616_REV
);
2306 ASSERT(texelBytes
== 4);
2308 if (!ctx
->_ImageTransferState
&&
2309 !srcPacking
->SwapBytes
&&
2310 ((dstFormat
== MESA_FORMAT_AL1616
&&
2311 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2312 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2313 (dstFormat
== MESA_FORMAT_RG1616
&&
2314 baseInternalFormat
== srcFormat
)) &&
2315 srcType
== GL_UNSIGNED_SHORT
&&
2317 /* simple memcpy path */
2318 memcpy_texture(ctx
, dims
,
2319 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2322 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2323 srcAddr
, srcPacking
);
2327 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2330 srcWidth
, srcHeight
, srcDepth
,
2331 srcFormat
, srcType
, srcAddr
,
2333 ctx
->_ImageTransferState
);
2334 const GLfloat
*src
= tempImage
;
2335 GLint img
, row
, col
;
2338 for (img
= 0; img
< srcDepth
; img
++) {
2339 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2340 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2341 + dstYoffset
* dstRowStride
2342 + dstXoffset
* texelBytes
;
2343 for (row
= 0; row
< srcHeight
; row
++) {
2344 GLuint
*dstUI
= (GLuint
*) dstRow
;
2345 if (dstFormat
== MESA_FORMAT_AL1616
||
2346 dstFormat
== MESA_FORMAT_RG1616
) {
2347 for (col
= 0; col
< srcWidth
; col
++) {
2350 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2351 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2352 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2357 for (col
= 0; col
< srcWidth
; col
++) {
2360 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2361 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2362 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2366 dstRow
+= dstRowStride
;
2369 free((void *) tempImage
);
2375 /* Texstore for R16, A16, L16, I16. */
2377 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2379 const GLboolean littleEndian
= _mesa_little_endian();
2380 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2381 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2383 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2384 dstFormat
== MESA_FORMAT_A16
||
2385 dstFormat
== MESA_FORMAT_L16
||
2386 dstFormat
== MESA_FORMAT_I16
);
2387 ASSERT(texelBytes
== 2);
2389 if (!ctx
->_ImageTransferState
&&
2390 !srcPacking
->SwapBytes
&&
2391 baseInternalFormat
== srcFormat
&&
2392 srcType
== GL_UNSIGNED_SHORT
&&
2394 /* simple memcpy path */
2395 memcpy_texture(ctx
, dims
,
2396 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2399 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2400 srcAddr
, srcPacking
);
2404 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2407 srcWidth
, srcHeight
, srcDepth
,
2408 srcFormat
, srcType
, srcAddr
,
2410 ctx
->_ImageTransferState
);
2411 const GLfloat
*src
= tempImage
;
2412 GLint img
, row
, col
;
2415 for (img
= 0; img
< srcDepth
; img
++) {
2416 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2417 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2418 + dstYoffset
* dstRowStride
2419 + dstXoffset
* texelBytes
;
2420 for (row
= 0; row
< srcHeight
; row
++) {
2421 GLushort
*dstUS
= (GLushort
*) dstRow
;
2422 for (col
= 0; col
< srcWidth
; col
++) {
2425 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2429 dstRow
+= dstRowStride
;
2432 free((void *) tempImage
);
2439 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2441 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2442 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2444 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2445 ASSERT(texelBytes
== 8);
2447 if (!ctx
->_ImageTransferState
&&
2448 !srcPacking
->SwapBytes
&&
2449 baseInternalFormat
== GL_RGBA
&&
2450 srcFormat
== GL_RGBA
&&
2451 srcType
== GL_UNSIGNED_SHORT
) {
2452 /* simple memcpy path */
2453 memcpy_texture(ctx
, dims
,
2454 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2457 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2458 srcAddr
, srcPacking
);
2462 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2465 srcWidth
, srcHeight
, srcDepth
,
2466 srcFormat
, srcType
, srcAddr
,
2468 ctx
->_ImageTransferState
);
2469 const GLfloat
*src
= tempImage
;
2470 GLint img
, row
, col
;
2473 for (img
= 0; img
< srcDepth
; img
++) {
2474 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2475 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2476 + dstYoffset
* dstRowStride
2477 + dstXoffset
* texelBytes
;
2478 for (row
= 0; row
< srcHeight
; row
++) {
2479 GLushort
*dstUS
= (GLushort
*) dstRow
;
2480 for (col
= 0; col
< srcWidth
; col
++) {
2481 GLushort r
, g
, b
, a
;
2483 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2484 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2485 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2486 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2493 dstRow
+= dstRowStride
;
2496 free((void *) tempImage
);
2503 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2505 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2506 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2508 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2509 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2511 if (!ctx
->_ImageTransferState
&&
2512 !srcPacking
->SwapBytes
&&
2513 baseInternalFormat
== GL_RGBA
&&
2514 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2515 srcFormat
== GL_RGBA
&&
2516 srcType
== GL_SHORT
) {
2517 /* simple memcpy path */
2518 memcpy_texture(ctx
, dims
,
2519 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2522 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2523 srcAddr
, srcPacking
);
2527 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2530 srcWidth
, srcHeight
, srcDepth
,
2531 srcFormat
, srcType
, srcAddr
,
2533 ctx
->_ImageTransferState
);
2534 const GLfloat
*src
= tempImage
;
2535 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2536 GLint img
, row
, col
;
2541 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2542 * 3 or 4 components/pixel here.
2544 for (img
= 0; img
< srcDepth
; img
++) {
2545 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2546 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2547 + dstYoffset
* dstRowStride
2548 + dstXoffset
* texelBytes
;
2549 for (row
= 0; row
< srcHeight
; row
++) {
2550 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2551 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2552 for (col
= 0; col
< srcWidth
; col
++) {
2554 for (c
= 0; c
< comps
; c
++) {
2556 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2557 dstRowS
[col
* comps
+ c
] = p
;
2560 dstRow
+= dstRowStride
;
2561 src
+= 4 * srcWidth
;
2563 for (col
= 0; col
< srcWidth
; col
++) {
2565 for (c
= 0; c
< comps
; c
++) {
2567 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2568 dstRowS
[col
* comps
+ c
] = p
;
2571 dstRow
+= dstRowStride
;
2572 src
+= 3 * srcWidth
;
2576 free((void *) tempImage
);
2583 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2585 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2586 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2588 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2589 ASSERT(texelBytes
== 1);
2591 if (!ctx
->_ImageTransferState
&&
2592 !srcPacking
->SwapBytes
&&
2593 baseInternalFormat
== GL_RGB
&&
2594 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2595 /* simple memcpy path */
2596 memcpy_texture(ctx
, dims
,
2597 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2600 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2601 srcAddr
, srcPacking
);
2605 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2608 srcWidth
, srcHeight
, srcDepth
,
2609 srcFormat
, srcType
, srcAddr
,
2611 const GLchan
*src
= tempImage
;
2612 GLint img
, row
, col
;
2615 for (img
= 0; img
< srcDepth
; img
++) {
2616 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2617 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2618 + dstYoffset
* dstRowStride
2619 + dstXoffset
* texelBytes
;
2620 for (row
= 0; row
< srcHeight
; row
++) {
2621 for (col
= 0; col
< srcWidth
; col
++) {
2622 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2623 CHAN_TO_UBYTE(src
[GCOMP
]),
2624 CHAN_TO_UBYTE(src
[BCOMP
]) );
2627 dstRow
+= dstRowStride
;
2630 free((void *) tempImage
);
2637 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2640 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2642 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2643 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2645 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2646 dstFormat
== MESA_FORMAT_L8
||
2647 dstFormat
== MESA_FORMAT_I8
||
2648 dstFormat
== MESA_FORMAT_R8
);
2649 ASSERT(texelBytes
== 1);
2651 if (!ctx
->_ImageTransferState
&&
2652 !srcPacking
->SwapBytes
&&
2653 baseInternalFormat
== srcFormat
&&
2654 srcType
== GL_UNSIGNED_BYTE
) {
2655 /* simple memcpy path */
2656 memcpy_texture(ctx
, dims
,
2657 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2660 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2661 srcAddr
, srcPacking
);
2663 else if (!ctx
->_ImageTransferState
&&
2664 srcType
== GL_UNSIGNED_BYTE
&&
2665 can_swizzle(baseInternalFormat
) &&
2666 can_swizzle(srcFormat
)) {
2669 /* dstmap - how to swizzle from RGBA to dst format:
2671 if (dstFormat
== MESA_FORMAT_A8
) {
2677 dstmap
[1] = ZERO
; /* ? */
2678 dstmap
[2] = ZERO
; /* ? */
2679 dstmap
[3] = ONE
; /* ? */
2681 _mesa_swizzle_ubyte_image(ctx
, dims
,
2686 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2687 dstRowStride
, dstImageOffsets
,
2688 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2693 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2696 srcWidth
, srcHeight
, srcDepth
,
2697 srcFormat
, srcType
, srcAddr
,
2699 const GLchan
*src
= tempImage
;
2700 GLint img
, row
, col
;
2703 for (img
= 0; img
< srcDepth
; img
++) {
2704 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2705 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2706 + dstYoffset
* dstRowStride
2707 + dstXoffset
* texelBytes
;
2708 for (row
= 0; row
< srcHeight
; row
++) {
2709 for (col
= 0; col
< srcWidth
; col
++) {
2710 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2712 dstRow
+= dstRowStride
;
2716 free((void *) tempImage
);
2724 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2726 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2728 (void) dims
; (void) baseInternalFormat
;
2729 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2730 ASSERT(texelBytes
== 1);
2731 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2733 if (!ctx
->_ImageTransferState
&&
2734 !srcPacking
->SwapBytes
&&
2735 srcFormat
== GL_COLOR_INDEX
&&
2736 srcType
== GL_UNSIGNED_BYTE
) {
2737 /* simple memcpy path */
2738 memcpy_texture(ctx
, dims
,
2739 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2742 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2743 srcAddr
, srcPacking
);
2748 for (img
= 0; img
< srcDepth
; img
++) {
2749 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2750 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2751 + dstYoffset
* dstRowStride
2752 + dstXoffset
* texelBytes
;
2753 for (row
= 0; row
< srcHeight
; row
++) {
2754 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2755 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2756 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2757 srcType
, src
, srcPacking
,
2758 ctx
->_ImageTransferState
);
2759 dstRow
+= dstRowStride
;
2768 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2771 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2773 const GLboolean littleEndian
= _mesa_little_endian();
2774 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2776 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2778 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2779 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2780 ASSERT(texelBytes
== 2);
2781 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2782 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2783 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2784 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2785 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2787 /* always just memcpy since no pixel transfer ops apply */
2788 memcpy_texture(ctx
, dims
,
2789 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2792 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2793 srcAddr
, srcPacking
);
2795 /* Check if we need byte swapping */
2796 /* XXX the logic here _might_ be wrong */
2797 if (srcPacking
->SwapBytes
^
2798 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2799 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2802 for (img
= 0; img
< srcDepth
; img
++) {
2803 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2804 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2805 + dstYoffset
* dstRowStride
2806 + dstXoffset
* texelBytes
;
2807 for (row
= 0; row
< srcHeight
; row
++) {
2808 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2809 dstRow
+= dstRowStride
;
2817 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2819 const GLboolean littleEndian
= _mesa_little_endian();
2820 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2822 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2823 ASSERT(texelBytes
== 2);
2824 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2825 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2826 (srcFormat
== GL_DUDV_ATI
));
2827 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2829 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2831 /* simple memcpy path */
2832 memcpy_texture(ctx
, dims
,
2833 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2836 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2837 srcAddr
, srcPacking
);
2839 else if (srcType
== GL_BYTE
) {
2842 /* dstmap - how to swizzle from RGBA to dst format:
2852 dstmap
[2] = ZERO
; /* ? */
2853 dstmap
[3] = ONE
; /* ? */
2855 _mesa_swizzle_ubyte_image(ctx
, dims
,
2856 GL_LUMINANCE_ALPHA
, /* hack */
2857 GL_UNSIGNED_BYTE
, /* hack */
2858 GL_LUMINANCE_ALPHA
, /* hack */
2860 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2861 dstRowStride
, dstImageOffsets
,
2862 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2866 /* general path - note this is defined for 2d textures only */
2867 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2868 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2869 srcFormat
, srcType
);
2870 GLbyte
*tempImage
, *dst
, *src
;
2873 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2874 * components
* sizeof(GLbyte
));
2878 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2879 srcWidth
, srcHeight
,
2884 for (row
= 0; row
< srcHeight
; row
++) {
2885 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2886 dst
, srcFormat
, srcType
, src
,
2888 dst
+= srcWidth
* components
;
2893 dst
= (GLbyte
*) dstAddr
2894 + dstYoffset
* dstRowStride
2895 + dstXoffset
* texelBytes
;
2896 for (row
= 0; row
< srcHeight
; row
++) {
2897 memcpy(dst
, src
, srcWidth
* texelBytes
);
2898 dst
+= dstRowStride
;
2899 src
+= srcWidth
* texelBytes
;
2901 free((void *) tempImage
);
2908 * Store a texture in a signed normalized 8-bit format.
2911 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2913 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2914 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2916 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2917 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2918 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2919 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2920 ASSERT(texelBytes
== 1);
2922 if (!ctx
->_ImageTransferState
&&
2923 !srcPacking
->SwapBytes
&&
2924 baseInternalFormat
== srcFormat
&&
2925 srcType
== GL_BYTE
) {
2926 /* simple memcpy path */
2927 memcpy_texture(ctx
, dims
,
2928 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2931 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2932 srcAddr
, srcPacking
);
2936 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2939 srcWidth
, srcHeight
, srcDepth
,
2940 srcFormat
, srcType
, srcAddr
,
2942 ctx
->_ImageTransferState
);
2943 const GLfloat
*src
= tempImage
;
2944 GLint img
, row
, col
;
2947 for (img
= 0; img
< srcDepth
; img
++) {
2948 GLbyte
*dstRow
= (GLbyte
*) dstAddr
2949 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2950 + dstYoffset
* dstRowStride
2951 + dstXoffset
* texelBytes
;
2952 for (row
= 0; row
< srcHeight
; row
++) {
2953 for (col
= 0; col
< srcWidth
; col
++) {
2954 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2956 dstRow
+= dstRowStride
;
2960 free((void *) tempImage
);
2967 * Store a texture in a signed normalized two-channel 16-bit format.
2970 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2972 const GLboolean littleEndian
= _mesa_little_endian();
2973 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2974 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2976 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2977 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2978 ASSERT(texelBytes
== 2);
2980 if (!ctx
->_ImageTransferState
&&
2981 !srcPacking
->SwapBytes
&&
2982 baseInternalFormat
== srcFormat
&&
2983 srcType
== GL_BYTE
&&
2985 /* simple memcpy path */
2986 memcpy_texture(ctx
, dims
,
2987 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2990 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2991 srcAddr
, srcPacking
);
2995 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2998 srcWidth
, srcHeight
, srcDepth
,
2999 srcFormat
, srcType
, srcAddr
,
3001 ctx
->_ImageTransferState
);
3002 const GLfloat
*src
= tempImage
;
3003 GLint img
, row
, col
;
3006 for (img
= 0; img
< srcDepth
; img
++) {
3007 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3008 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3009 + dstYoffset
* dstRowStride
3010 + dstXoffset
* texelBytes
;
3011 for (row
= 0; row
< srcHeight
; row
++) {
3012 GLbyte
*dst
= dstRow
;
3013 for (col
= 0; col
< srcWidth
; col
++) {
3014 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
3015 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
3019 dstRow
+= dstRowStride
;
3022 free((void *) tempImage
);
3027 /* Texstore for signed R16, A16, L16, I16. */
3029 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
3031 const GLboolean littleEndian
= _mesa_little_endian();
3032 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3033 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3035 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
3036 dstFormat
== MESA_FORMAT_SIGNED_A16
||
3037 dstFormat
== MESA_FORMAT_SIGNED_L16
||
3038 dstFormat
== MESA_FORMAT_SIGNED_I16
);
3039 ASSERT(texelBytes
== 2);
3041 if (!ctx
->_ImageTransferState
&&
3042 !srcPacking
->SwapBytes
&&
3043 baseInternalFormat
== srcFormat
&&
3044 srcType
== GL_SHORT
&&
3046 /* simple memcpy path */
3047 memcpy_texture(ctx
, dims
,
3048 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3051 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3052 srcAddr
, srcPacking
);
3056 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3059 srcWidth
, srcHeight
, srcDepth
,
3060 srcFormat
, srcType
, srcAddr
,
3062 ctx
->_ImageTransferState
);
3063 const GLfloat
*src
= tempImage
;
3064 GLint img
, row
, col
;
3067 for (img
= 0; img
< srcDepth
; img
++) {
3068 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3069 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3070 + dstYoffset
* dstRowStride
3071 + dstXoffset
* texelBytes
;
3072 for (row
= 0; row
< srcHeight
; row
++) {
3073 GLshort
*dstUS
= (GLshort
*) dstRow
;
3074 for (col
= 0; col
< srcWidth
; col
++) {
3077 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
3081 dstRow
+= dstRowStride
;
3084 free((void *) tempImage
);
3090 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
3093 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
3095 const GLboolean littleEndian
= _mesa_little_endian();
3096 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3097 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3099 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
3100 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
3101 ASSERT(texelBytes
== 4);
3103 if (!ctx
->_ImageTransferState
&&
3104 !srcPacking
->SwapBytes
&&
3105 baseInternalFormat
== srcFormat
&&
3106 srcType
== GL_SHORT
&&
3108 /* simple memcpy path */
3109 memcpy_texture(ctx
, dims
,
3110 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3113 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3114 srcAddr
, srcPacking
);
3118 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3121 srcWidth
, srcHeight
, srcDepth
,
3122 srcFormat
, srcType
, srcAddr
,
3124 ctx
->_ImageTransferState
);
3125 const GLfloat
*src
= tempImage
;
3126 GLint img
, row
, col
;
3129 for (img
= 0; img
< srcDepth
; img
++) {
3130 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3131 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3132 + dstYoffset
* dstRowStride
3133 + dstXoffset
* texelBytes
;
3134 for (row
= 0; row
< srcHeight
; row
++) {
3135 GLshort
*dst
= (GLshort
*) dstRow
;
3136 for (col
= 0; col
< srcWidth
; col
++) {
3139 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
3140 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
3146 dstRow
+= dstRowStride
;
3149 free((void *) tempImage
);
3155 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
3158 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
3160 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3161 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3163 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
3164 ASSERT(texelBytes
== 4);
3168 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3171 srcWidth
, srcHeight
, srcDepth
,
3172 srcFormat
, srcType
, srcAddr
,
3174 ctx
->_ImageTransferState
);
3175 const GLfloat
*srcRow
= tempImage
;
3176 GLint img
, row
, col
;
3179 for (img
= 0; img
< srcDepth
; img
++) {
3180 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3181 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3182 + dstYoffset
* dstRowStride
3183 + dstXoffset
* texelBytes
;
3184 for (row
= 0; row
< srcHeight
; row
++) {
3185 GLbyte
*dst
= dstRow
;
3186 for (col
= 0; col
< srcWidth
; col
++) {
3187 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3188 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3189 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3194 dstRow
+= dstRowStride
;
3197 free((void *) tempImage
);
3205 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3206 * MESA_FORMAT_SIGNED_RGBA8888_REV
3209 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3211 const GLboolean littleEndian
= _mesa_little_endian();
3212 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3213 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3215 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3216 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3217 ASSERT(texelBytes
== 4);
3219 if (!ctx
->_ImageTransferState
&&
3220 !srcPacking
->SwapBytes
&&
3221 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3222 baseInternalFormat
== GL_RGBA
&&
3223 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3224 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3225 /* simple memcpy path */
3226 memcpy_texture(ctx
, dims
,
3227 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3230 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3231 srcAddr
, srcPacking
);
3233 else if (!ctx
->_ImageTransferState
&&
3234 !srcPacking
->SwapBytes
&&
3235 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3236 baseInternalFormat
== GL_RGBA
&&
3237 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3238 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3239 /* simple memcpy path */
3240 memcpy_texture(ctx
, dims
,
3241 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3244 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3245 srcAddr
, srcPacking
);
3249 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3252 srcWidth
, srcHeight
, srcDepth
,
3253 srcFormat
, srcType
, srcAddr
,
3255 ctx
->_ImageTransferState
);
3256 const GLfloat
*srcRow
= tempImage
;
3257 GLint img
, row
, col
;
3260 for (img
= 0; img
< srcDepth
; img
++) {
3261 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3262 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3263 + dstYoffset
* dstRowStride
3264 + dstXoffset
* texelBytes
;
3265 for (row
= 0; row
< srcHeight
; row
++) {
3266 GLbyte
*dst
= dstRow
;
3267 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3268 for (col
= 0; col
< srcWidth
; col
++) {
3269 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3270 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3271 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3272 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3278 for (col
= 0; col
< srcWidth
; col
++) {
3279 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3280 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3281 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3282 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3287 dstRow
+= dstRowStride
;
3290 free((void *) tempImage
);
3297 * Store a combined depth/stencil texture image.
3300 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3302 const GLuint depthScale
= 0xffffff;
3303 const GLint srcRowStride
3304 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3308 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3309 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
3310 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3312 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3313 ctx
->Pixel
.DepthBias
== 0.0f
&&
3314 !srcPacking
->SwapBytes
) {
3316 memcpy_texture(ctx
, dims
,
3317 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3320 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3321 srcAddr
, srcPacking
);
3323 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
3324 /* In case we only upload depth we need to preserve the stencil */
3325 for (img
= 0; img
< srcDepth
; img
++) {
3326 GLuint
*dstRow
= (GLuint
*) dstAddr
3327 + dstImageOffsets
[dstZoffset
+ img
]
3328 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3331 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3332 srcWidth
, srcHeight
,
3335 for (row
= 0; row
< srcHeight
; row
++) {
3336 GLuint depth
[MAX_WIDTH
];
3337 GLubyte stencil
[MAX_WIDTH
];
3339 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3341 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3342 keepstencil
= GL_TRUE
;
3344 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3345 keepdepth
= GL_TRUE
;
3348 if (keepdepth
== GL_FALSE
)
3349 /* the 24 depth bits will be in the low position: */
3350 _mesa_unpack_depth_span(ctx
, srcWidth
,
3351 GL_UNSIGNED_INT
, /* dst type */
3352 keepstencil
? depth
: dstRow
, /* dst addr */
3354 srcType
, src
, srcPacking
);
3356 if (keepstencil
== GL_FALSE
)
3357 /* get the 8-bit stencil values */
3358 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3359 GL_UNSIGNED_BYTE
, /* dst type */
3360 stencil
, /* dst addr */
3361 srcType
, src
, srcPacking
,
3362 ctx
->_ImageTransferState
);
3364 for (i
= 0; i
< srcWidth
; i
++) {
3366 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3368 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3371 src
+= srcRowStride
;
3372 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3381 * Store a combined depth/stencil texture image.
3384 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3386 const GLuint depthScale
= 0xffffff;
3387 const GLint srcRowStride
3388 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3392 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3393 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3394 srcFormat
== GL_DEPTH_COMPONENT
||
3395 srcFormat
== GL_STENCIL_INDEX
);
3396 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3397 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3399 for (img
= 0; img
< srcDepth
; img
++) {
3400 GLuint
*dstRow
= (GLuint
*) dstAddr
3401 + dstImageOffsets
[dstZoffset
+ img
]
3402 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3405 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3406 srcWidth
, srcHeight
,
3409 for (row
= 0; row
< srcHeight
; row
++) {
3410 GLuint depth
[MAX_WIDTH
];
3411 GLubyte stencil
[MAX_WIDTH
];
3413 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3415 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3416 keepstencil
= GL_TRUE
;
3418 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3419 keepdepth
= GL_TRUE
;
3422 if (keepdepth
== GL_FALSE
)
3423 /* the 24 depth bits will be in the low position: */
3424 _mesa_unpack_depth_span(ctx
, srcWidth
,
3425 GL_UNSIGNED_INT
, /* dst type */
3426 keepstencil
? depth
: dstRow
, /* dst addr */
3428 srcType
, src
, srcPacking
);
3430 if (keepstencil
== GL_FALSE
)
3431 /* get the 8-bit stencil values */
3432 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3433 GL_UNSIGNED_BYTE
, /* dst type */
3434 stencil
, /* dst addr */
3435 srcType
, src
, srcPacking
,
3436 ctx
->_ImageTransferState
);
3438 /* merge stencil values into depth values */
3439 for (i
= 0; i
< srcWidth
; i
++) {
3441 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3443 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3446 src
+= srcRowStride
;
3447 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3455 * Store simple 8-bit/value stencil texture data.
3458 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3460 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3461 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3463 if (!ctx
->_ImageTransferState
&&
3464 !srcPacking
->SwapBytes
&&
3465 baseInternalFormat
== srcFormat
&&
3466 srcType
== GL_UNSIGNED_BYTE
) {
3467 /* simple memcpy path */
3468 memcpy_texture(ctx
, dims
,
3469 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3472 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3473 srcAddr
, srcPacking
);
3476 const GLint srcRowStride
3477 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3481 for (img
= 0; img
< srcDepth
; img
++) {
3482 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3483 + dstImageOffsets
[dstZoffset
+ img
]
3484 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3487 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3488 srcWidth
, srcHeight
,
3491 for (row
= 0; row
< srcHeight
; row
++) {
3492 GLubyte stencil
[MAX_WIDTH
];
3495 /* get the 8-bit stencil values */
3496 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3497 GL_UNSIGNED_BYTE
, /* dst type */
3498 stencil
, /* dst addr */
3499 srcType
, src
, srcPacking
,
3500 ctx
->_ImageTransferState
);
3501 /* merge stencil values into depth values */
3502 for (i
= 0; i
< srcWidth
; i
++)
3503 dstRow
[i
] = stencil
[i
];
3505 src
+= srcRowStride
;
3506 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3517 * Store an image in any of the formats:
3518 * _mesa_texformat_rgba_float32
3519 * _mesa_texformat_rgb_float32
3520 * _mesa_texformat_alpha_float32
3521 * _mesa_texformat_luminance_float32
3522 * _mesa_texformat_luminance_alpha_float32
3523 * _mesa_texformat_intensity_float32
3526 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3528 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3529 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3530 const GLint components
= _mesa_components_in_format(baseFormat
);
3532 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3533 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3534 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3535 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3536 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3537 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3538 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3539 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3540 ASSERT(baseInternalFormat
== GL_RGBA
||
3541 baseInternalFormat
== GL_RGB
||
3542 baseInternalFormat
== GL_ALPHA
||
3543 baseInternalFormat
== GL_LUMINANCE
||
3544 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3545 baseInternalFormat
== GL_INTENSITY
||
3546 baseInternalFormat
== GL_RED
||
3547 baseInternalFormat
== GL_RG
);
3548 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3550 if (!ctx
->_ImageTransferState
&&
3551 !srcPacking
->SwapBytes
&&
3552 baseInternalFormat
== srcFormat
&&
3553 baseInternalFormat
== baseFormat
&&
3554 srcType
== GL_FLOAT
) {
3555 /* simple memcpy path */
3556 memcpy_texture(ctx
, dims
,
3557 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3560 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3561 srcAddr
, srcPacking
);
3565 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3568 srcWidth
, srcHeight
, srcDepth
,
3569 srcFormat
, srcType
, srcAddr
,
3571 ctx
->_ImageTransferState
);
3572 const GLfloat
*srcRow
= tempImage
;
3577 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3578 for (img
= 0; img
< srcDepth
; img
++) {
3579 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3580 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3581 + dstYoffset
* dstRowStride
3582 + dstXoffset
* texelBytes
;
3583 for (row
= 0; row
< srcHeight
; row
++) {
3584 memcpy(dstRow
, srcRow
, bytesPerRow
);
3585 dstRow
+= dstRowStride
;
3586 srcRow
+= srcWidth
* components
;
3590 free((void *) tempImage
);
3598 * As above, but store 16-bit floats.
3601 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3603 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3604 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3605 const GLint components
= _mesa_components_in_format(baseFormat
);
3607 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3608 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3609 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3610 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3611 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3612 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3613 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3614 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3615 ASSERT(baseInternalFormat
== GL_RGBA
||
3616 baseInternalFormat
== GL_RGB
||
3617 baseInternalFormat
== GL_ALPHA
||
3618 baseInternalFormat
== GL_LUMINANCE
||
3619 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3620 baseInternalFormat
== GL_INTENSITY
||
3621 baseInternalFormat
== GL_RED
||
3622 baseInternalFormat
== GL_RG
);
3623 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3625 if (!ctx
->_ImageTransferState
&&
3626 !srcPacking
->SwapBytes
&&
3627 baseInternalFormat
== srcFormat
&&
3628 baseInternalFormat
== baseFormat
&&
3629 srcType
== GL_HALF_FLOAT_ARB
) {
3630 /* simple memcpy path */
3631 memcpy_texture(ctx
, dims
,
3632 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3635 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3636 srcAddr
, srcPacking
);
3640 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3643 srcWidth
, srcHeight
, srcDepth
,
3644 srcFormat
, srcType
, srcAddr
,
3646 ctx
->_ImageTransferState
);
3647 const GLfloat
*src
= tempImage
;
3651 for (img
= 0; img
< srcDepth
; img
++) {
3652 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3653 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3654 + dstYoffset
* dstRowStride
3655 + dstXoffset
* texelBytes
;
3656 for (row
= 0; row
< srcHeight
; row
++) {
3657 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3659 for (i
= 0; i
< srcWidth
* components
; i
++) {
3660 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3662 dstRow
+= dstRowStride
;
3663 src
+= srcWidth
* components
;
3667 free((void *) tempImage
);
3673 /* non-normalized, signed int8 */
3675 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3677 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3678 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3679 const GLint components
= _mesa_components_in_format(baseFormat
);
3681 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3682 ASSERT(baseInternalFormat
== GL_RGBA
||
3683 baseInternalFormat
== GL_RGB
||
3684 baseInternalFormat
== GL_ALPHA
||
3685 baseInternalFormat
== GL_LUMINANCE
||
3686 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3687 baseInternalFormat
== GL_INTENSITY
);
3688 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3690 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3691 * to integer formats.
3693 if (!srcPacking
->SwapBytes
&&
3694 baseInternalFormat
== srcFormat
&&
3695 srcType
== GL_BYTE
) {
3696 /* simple memcpy path */
3697 memcpy_texture(ctx
, dims
,
3698 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3701 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3702 srcAddr
, srcPacking
);
3706 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3709 srcWidth
, srcHeight
, srcDepth
,
3710 srcFormat
, srcType
, srcAddr
,
3712 const GLfloat
*src
= tempImage
;
3716 for (img
= 0; img
< srcDepth
; img
++) {
3717 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3718 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3719 + dstYoffset
* dstRowStride
3720 + dstXoffset
* texelBytes
;
3721 for (row
= 0; row
< srcHeight
; row
++) {
3722 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3724 for (i
= 0; i
< srcWidth
* components
; i
++) {
3725 dstTexel
[i
] = (GLbyte
) src
[i
];
3727 dstRow
+= dstRowStride
;
3728 src
+= srcWidth
* components
;
3732 free((void *) tempImage
);
3738 /* non-normalized, signed int16 */
3740 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3742 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3743 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3744 const GLint components
= _mesa_components_in_format(baseFormat
);
3746 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3747 ASSERT(baseInternalFormat
== GL_RGBA
||
3748 baseInternalFormat
== GL_RGB
||
3749 baseInternalFormat
== GL_ALPHA
||
3750 baseInternalFormat
== GL_LUMINANCE
||
3751 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3752 baseInternalFormat
== GL_INTENSITY
);
3753 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3755 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3756 * to integer formats.
3758 if (!srcPacking
->SwapBytes
&&
3759 baseInternalFormat
== srcFormat
&&
3760 srcType
== GL_SHORT
) {
3761 /* simple memcpy path */
3762 memcpy_texture(ctx
, dims
,
3763 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3766 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3767 srcAddr
, srcPacking
);
3771 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3774 srcWidth
, srcHeight
, srcDepth
,
3775 srcFormat
, srcType
, srcAddr
,
3777 const GLfloat
*src
= tempImage
;
3781 for (img
= 0; img
< srcDepth
; img
++) {
3782 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3783 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3784 + dstYoffset
* dstRowStride
3785 + dstXoffset
* texelBytes
;
3786 for (row
= 0; row
< srcHeight
; row
++) {
3787 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3789 for (i
= 0; i
< srcWidth
* components
; i
++) {
3790 dstTexel
[i
] = (GLint
) src
[i
];
3792 dstRow
+= dstRowStride
;
3793 src
+= srcWidth
* components
;
3797 free((void *) tempImage
);
3803 /* non-normalized, signed int32 */
3805 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3807 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3808 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3809 const GLint components
= _mesa_components_in_format(baseFormat
);
3811 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3812 ASSERT(baseInternalFormat
== GL_RGBA
||
3813 baseInternalFormat
== GL_RGB
||
3814 baseInternalFormat
== GL_ALPHA
||
3815 baseInternalFormat
== GL_LUMINANCE
||
3816 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3817 baseInternalFormat
== GL_INTENSITY
);
3818 ASSERT(texelBytes
== components
* sizeof(GLint
));
3820 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3821 * to integer formats.
3823 if (!srcPacking
->SwapBytes
&&
3824 baseInternalFormat
== srcFormat
&&
3825 srcType
== GL_INT
) {
3826 /* simple memcpy path */
3827 memcpy_texture(ctx
, dims
,
3828 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3831 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3832 srcAddr
, srcPacking
);
3836 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3839 srcWidth
, srcHeight
, srcDepth
,
3840 srcFormat
, srcType
, srcAddr
,
3842 const GLfloat
*src
= tempImage
;
3846 for (img
= 0; img
< srcDepth
; img
++) {
3847 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3848 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3849 + dstYoffset
* dstRowStride
3850 + dstXoffset
* texelBytes
;
3851 for (row
= 0; row
< srcHeight
; row
++) {
3852 GLint
*dstTexel
= (GLint
*) dstRow
;
3854 for (i
= 0; i
< srcWidth
* components
; i
++) {
3855 dstTexel
[i
] = (GLint
) src
[i
];
3857 dstRow
+= dstRowStride
;
3858 src
+= srcWidth
* components
;
3862 free((void *) tempImage
);
3868 /* non-normalized, unsigned int8 */
3870 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3872 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3873 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3874 const GLint components
= _mesa_components_in_format(baseFormat
);
3876 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3877 ASSERT(baseInternalFormat
== GL_RGBA
||
3878 baseInternalFormat
== GL_RGB
||
3879 baseInternalFormat
== GL_ALPHA
||
3880 baseInternalFormat
== GL_LUMINANCE
||
3881 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3882 baseInternalFormat
== GL_INTENSITY
);
3883 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3885 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3886 * to integer formats.
3888 if (!srcPacking
->SwapBytes
&&
3889 baseInternalFormat
== srcFormat
&&
3890 srcType
== GL_UNSIGNED_BYTE
) {
3891 /* simple memcpy path */
3892 memcpy_texture(ctx
, dims
,
3893 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3896 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3897 srcAddr
, srcPacking
);
3901 const GLuint
*tempImage
=
3902 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3903 srcWidth
, srcHeight
, srcDepth
,
3904 srcFormat
, srcType
, srcAddr
, srcPacking
);
3905 const GLuint
*src
= tempImage
;
3909 for (img
= 0; img
< srcDepth
; img
++) {
3910 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3911 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3912 + dstYoffset
* dstRowStride
3913 + dstXoffset
* texelBytes
;
3914 for (row
= 0; row
< srcHeight
; row
++) {
3915 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3917 for (i
= 0; i
< srcWidth
* components
; i
++) {
3918 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3920 dstRow
+= dstRowStride
;
3921 src
+= srcWidth
* components
;
3925 free((void *) tempImage
);
3931 /* non-normalized, unsigned int16 */
3933 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3935 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3936 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3937 const GLint components
= _mesa_components_in_format(baseFormat
);
3939 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3940 ASSERT(baseInternalFormat
== GL_RGBA
||
3941 baseInternalFormat
== GL_RGB
||
3942 baseInternalFormat
== GL_ALPHA
||
3943 baseInternalFormat
== GL_LUMINANCE
||
3944 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3945 baseInternalFormat
== GL_INTENSITY
);
3946 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3948 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3949 * to integer formats.
3951 if (!srcPacking
->SwapBytes
&&
3952 baseInternalFormat
== srcFormat
&&
3953 srcType
== GL_UNSIGNED_SHORT
) {
3954 /* simple memcpy path */
3955 memcpy_texture(ctx
, dims
,
3956 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3959 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3960 srcAddr
, srcPacking
);
3964 const GLuint
*tempImage
=
3965 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3966 srcWidth
, srcHeight
, srcDepth
,
3967 srcFormat
, srcType
, srcAddr
, srcPacking
);
3968 const GLuint
*src
= tempImage
;
3972 for (img
= 0; img
< srcDepth
; img
++) {
3973 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3974 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3975 + dstYoffset
* dstRowStride
3976 + dstXoffset
* texelBytes
;
3977 for (row
= 0; row
< srcHeight
; row
++) {
3978 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3980 for (i
= 0; i
< srcWidth
* components
; i
++) {
3981 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3983 dstRow
+= dstRowStride
;
3984 src
+= srcWidth
* components
;
3988 free((void *) tempImage
);
3994 /* non-normalized, unsigned int32 */
3996 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3998 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3999 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4000 const GLint components
= _mesa_components_in_format(baseFormat
);
4002 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
4003 ASSERT(baseInternalFormat
== GL_RGBA
||
4004 baseInternalFormat
== GL_RGB
||
4005 baseInternalFormat
== GL_ALPHA
||
4006 baseInternalFormat
== GL_LUMINANCE
||
4007 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
4008 baseInternalFormat
== GL_INTENSITY
);
4009 ASSERT(texelBytes
== components
* sizeof(GLuint
));
4011 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
4012 * to integer formats.
4014 if (!srcPacking
->SwapBytes
&&
4015 baseInternalFormat
== srcFormat
&&
4016 srcType
== GL_UNSIGNED_INT
) {
4017 /* simple memcpy path */
4018 memcpy_texture(ctx
, dims
,
4019 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4022 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4023 srcAddr
, srcPacking
);
4027 const GLuint
*tempImage
=
4028 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
4029 srcWidth
, srcHeight
, srcDepth
,
4030 srcFormat
, srcType
, srcAddr
, srcPacking
);
4031 const GLuint
*src
= tempImage
;
4035 for (img
= 0; img
< srcDepth
; img
++) {
4036 GLubyte
*dstRow
= (GLubyte
*) dstAddr
4037 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
4038 + dstYoffset
* dstRowStride
4039 + dstXoffset
* texelBytes
;
4040 for (row
= 0; row
< srcHeight
; row
++) {
4041 GLuint
*dstTexel
= (GLuint
*) dstRow
;
4043 for (i
= 0; i
< srcWidth
* components
; i
++) {
4044 dstTexel
[i
] = src
[i
];
4046 dstRow
+= dstRowStride
;
4047 src
+= srcWidth
* components
;
4051 free((void *) tempImage
);
4059 #if FEATURE_EXT_texture_sRGB
4061 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
4063 gl_format newDstFormat
;
4066 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
4068 /* reuse normal rgb texstore code */
4069 newDstFormat
= MESA_FORMAT_RGB888
;
4071 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
4072 newDstFormat
, dstAddr
,
4073 dstXoffset
, dstYoffset
, dstZoffset
,
4074 dstRowStride
, dstImageOffsets
,
4075 srcWidth
, srcHeight
, srcDepth
,
4077 srcAddr
, srcPacking
);
4083 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
4085 gl_format newDstFormat
;
4088 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
4090 /* reuse normal rgba texstore code */
4091 newDstFormat
= MESA_FORMAT_RGBA8888
;
4092 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
4093 newDstFormat
, dstAddr
,
4094 dstXoffset
, dstYoffset
, dstZoffset
,
4095 dstRowStride
, dstImageOffsets
,
4096 srcWidth
, srcHeight
, srcDepth
,
4098 srcAddr
, srcPacking
);
4104 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
4106 gl_format newDstFormat
;
4109 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
4111 /* reuse normal rgba texstore code */
4112 newDstFormat
= MESA_FORMAT_ARGB8888
;
4114 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
4115 newDstFormat
, dstAddr
,
4116 dstXoffset
, dstYoffset
, dstZoffset
,
4117 dstRowStride
, dstImageOffsets
,
4118 srcWidth
, srcHeight
, srcDepth
,
4120 srcAddr
, srcPacking
);
4126 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
4128 gl_format newDstFormat
;
4131 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
4133 newDstFormat
= MESA_FORMAT_L8
;
4135 /* _mesa_textore_a8 handles luminance8 too */
4136 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
4137 newDstFormat
, dstAddr
,
4138 dstXoffset
, dstYoffset
, dstZoffset
,
4139 dstRowStride
, dstImageOffsets
,
4140 srcWidth
, srcHeight
, srcDepth
,
4142 srcAddr
, srcPacking
);
4148 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
4150 gl_format newDstFormat
;
4153 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4155 /* reuse normal luminance/alpha texstore code */
4156 newDstFormat
= MESA_FORMAT_AL88
;
4158 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4159 newDstFormat
, dstAddr
,
4160 dstXoffset
, dstYoffset
, dstZoffset
,
4161 dstRowStride
, dstImageOffsets
,
4162 srcWidth
, srcHeight
, srcDepth
,
4164 srcAddr
, srcPacking
);
4170 /* these are used only in texstore_funcs[] below */
4171 #define _mesa_texstore_srgb8 NULL
4172 #define _mesa_texstore_srgba8 NULL
4173 #define _mesa_texstore_sargb8 NULL
4174 #define _mesa_texstore_sl8 NULL
4175 #define _mesa_texstore_sla8 NULL
4177 #endif /* FEATURE_EXT_texture_sRGB */
4183 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4184 * XXX this is somewhat temporary.
4186 static const struct {
4188 StoreTexImageFunc Store
;
4190 texstore_funcs
[MESA_FORMAT_COUNT
] =
4192 { MESA_FORMAT_NONE
, NULL
},
4193 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
4194 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
4195 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
4196 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
4197 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
4198 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
4199 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
4200 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
4201 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
4202 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
4203 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
4204 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
4205 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
4206 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
4207 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
4208 { MESA_FORMAT_AL44
, _mesa_texstore_unorm44
},
4209 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
4210 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
4211 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
4212 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
4213 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
4214 { MESA_FORMAT_A8
, _mesa_texstore_unorm8
},
4215 { MESA_FORMAT_A16
, _mesa_texstore_unorm16
},
4216 { MESA_FORMAT_L8
, _mesa_texstore_unorm8
},
4217 { MESA_FORMAT_L16
, _mesa_texstore_unorm16
},
4218 { MESA_FORMAT_I8
, _mesa_texstore_unorm8
},
4219 { MESA_FORMAT_I16
, _mesa_texstore_unorm16
},
4220 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
4221 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
4222 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
4223 { MESA_FORMAT_R8
, _mesa_texstore_unorm8
},
4224 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
4225 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
4226 { MESA_FORMAT_R16
, _mesa_texstore_unorm16
},
4227 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
4228 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
4229 { MESA_FORMAT_ARGB2101010
, _mesa_texstore_argb2101010
},
4230 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
4231 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
4232 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
4233 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
4234 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
4235 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
4236 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
4237 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
4238 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
4239 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
4240 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
4241 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
4242 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4243 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4244 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4245 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4246 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
4247 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
4248 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4249 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4250 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4251 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4252 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
4253 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
4254 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
4255 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
4256 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4257 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4258 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
4259 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
4260 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4261 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4262 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
4263 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
4264 { MESA_FORMAT_R_FLOAT32
, _mesa_texstore_rgba_float32
},
4265 { MESA_FORMAT_R_FLOAT16
, _mesa_texstore_rgba_float16
},
4266 { MESA_FORMAT_RG_FLOAT32
, _mesa_texstore_rgba_float32
},
4267 { MESA_FORMAT_RG_FLOAT16
, _mesa_texstore_rgba_float16
},
4269 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
4270 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
4271 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
4272 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
4273 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
4274 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
4276 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
4278 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_snorm8
},
4279 { MESA_FORMAT_SIGNED_RG88_REV
, _mesa_texstore_snorm88
},
4280 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
4282 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
4283 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
4285 { MESA_FORMAT_SIGNED_R16
, _mesa_texstore_snorm16
},
4286 { MESA_FORMAT_SIGNED_GR1616
, _mesa_texstore_snorm1616
},
4287 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
4288 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
4289 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
},
4291 { MESA_FORMAT_RED_RGTC1
, _mesa_texstore_red_rgtc1
},
4292 { MESA_FORMAT_SIGNED_RED_RGTC1
, _mesa_texstore_signed_red_rgtc1
},
4293 { MESA_FORMAT_RG_RGTC2
, _mesa_texstore_rg_rgtc2
},
4294 { MESA_FORMAT_SIGNED_RG_RGTC2
, _mesa_texstore_signed_rg_rgtc2
},
4296 /* Re-use the R/RG texstore functions.
4297 * The code is generic enough to handle LATC too. */
4298 { MESA_FORMAT_L_LATC1
, _mesa_texstore_red_rgtc1
},
4299 { MESA_FORMAT_SIGNED_L_LATC1
, _mesa_texstore_signed_red_rgtc1
},
4300 { MESA_FORMAT_LA_LATC2
, _mesa_texstore_rg_rgtc2
},
4301 { MESA_FORMAT_SIGNED_LA_LATC2
, _mesa_texstore_signed_rg_rgtc2
},
4303 { MESA_FORMAT_SIGNED_A8
, _mesa_texstore_snorm8
},
4304 { MESA_FORMAT_SIGNED_L8
, _mesa_texstore_snorm8
},
4305 { MESA_FORMAT_SIGNED_AL88
, _mesa_texstore_snorm88
},
4306 { MESA_FORMAT_SIGNED_I8
, _mesa_texstore_snorm8
},
4308 { MESA_FORMAT_SIGNED_A16
, _mesa_texstore_snorm16
},
4309 { MESA_FORMAT_SIGNED_L16
, _mesa_texstore_snorm16
},
4310 { MESA_FORMAT_SIGNED_AL1616
, _mesa_texstore_snorm1616
},
4311 { MESA_FORMAT_SIGNED_I16
, _mesa_texstore_snorm16
},
4316 _mesa_texstore_null(TEXSTORE_PARAMS
)
4318 (void) ctx
; (void) dims
;
4319 (void) baseInternalFormat
;
4322 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4323 (void) dstRowStride
; (void) dstImageOffsets
;
4324 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4325 (void) srcFormat
; (void) srcType
;
4329 /* should never happen */
4330 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4336 * Return the StoreTexImageFunc pointer to store an image in the given format.
4338 static StoreTexImageFunc
4339 _mesa_get_texstore_func(gl_format format
)
4343 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4344 ASSERT(texstore_funcs
[i
].Name
== i
);
4347 ASSERT(texstore_funcs
[format
].Name
== format
);
4349 if (texstore_funcs
[format
].Store
)
4350 return texstore_funcs
[format
].Store
;
4352 return _mesa_texstore_null
;
4357 * Store user data into texture memory.
4358 * Called via glTex[Sub]Image1/2/3D()
4361 _mesa_texstore(TEXSTORE_PARAMS
)
4363 StoreTexImageFunc storeImage
;
4366 storeImage
= _mesa_get_texstore_func(dstFormat
);
4368 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4369 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4370 dstRowStride
, dstImageOffsets
,
4371 srcWidth
, srcHeight
, srcDepth
,
4372 srcFormat
, srcType
, srcAddr
, srcPacking
);
4377 /** Return texture size in bytes */
4379 texture_size(const struct gl_texture_image
*texImage
)
4381 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4382 texImage
->Height
, texImage
->Depth
);
4387 /** Return row stride in bytes */
4389 texture_row_stride(const struct gl_texture_image
*texImage
)
4391 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4399 * This is the software fallback for Driver.TexImage1D()
4400 * and Driver.CopyTexImage1D().
4401 * \sa _mesa_store_teximage2d()
4404 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4405 GLint internalFormat
,
4406 GLint width
, GLint border
,
4407 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4408 const struct gl_pixelstore_attrib
*packing
,
4409 struct gl_texture_object
*texObj
,
4410 struct gl_texture_image
*texImage
)
4415 /* allocate memory */
4416 sizeInBytes
= texture_size(texImage
);
4417 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4418 if (!texImage
->Data
) {
4419 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4423 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4424 pixels
, packing
, "glTexImage1D");
4426 /* Note: we check for a NULL image pointer here, _after_ we allocated
4427 * memory for the texture. That's what the GL spec calls for.
4432 const GLint dstRowStride
= 0;
4433 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4434 texImage
->TexFormat
,
4436 0, 0, 0, /* dstX/Y/Zoffset */
4438 texImage
->ImageOffsets
,
4440 format
, type
, pixels
, packing
);
4442 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4446 _mesa_unmap_teximage_pbo(ctx
, packing
);
4451 * This is the software fallback for Driver.TexImage2D()
4452 * and Driver.CopyTexImage2D().
4454 * This function is oriented toward storing images in main memory, rather
4455 * than VRAM. Device driver's can easily plug in their own replacement.
4458 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4459 GLint internalFormat
,
4460 GLint width
, GLint height
, GLint border
,
4461 GLenum format
, GLenum type
, const void *pixels
,
4462 const struct gl_pixelstore_attrib
*packing
,
4463 struct gl_texture_object
*texObj
,
4464 struct gl_texture_image
*texImage
)
4469 /* allocate memory */
4470 sizeInBytes
= texture_size(texImage
);
4471 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4472 if (!texImage
->Data
) {
4473 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4477 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4478 pixels
, packing
, "glTexImage2D");
4480 /* Note: we check for a NULL image pointer here, _after_ we allocated
4481 * memory for the texture. That's what the GL spec calls for.
4486 GLint dstRowStride
= texture_row_stride(texImage
);
4487 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4488 texImage
->TexFormat
,
4490 0, 0, 0, /* dstX/Y/Zoffset */
4492 texImage
->ImageOffsets
,
4494 format
, type
, pixels
, packing
);
4496 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4500 _mesa_unmap_teximage_pbo(ctx
, packing
);
4506 * This is the software fallback for Driver.TexImage3D()
4507 * and Driver.CopyTexImage3D().
4508 * \sa _mesa_store_teximage2d()
4511 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4512 GLint internalFormat
,
4513 GLint width
, GLint height
, GLint depth
, GLint border
,
4514 GLenum format
, GLenum type
, const void *pixels
,
4515 const struct gl_pixelstore_attrib
*packing
,
4516 struct gl_texture_object
*texObj
,
4517 struct gl_texture_image
*texImage
)
4522 /* allocate memory */
4523 sizeInBytes
= texture_size(texImage
);
4524 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4525 if (!texImage
->Data
) {
4526 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4530 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4531 type
, pixels
, packing
, "glTexImage3D");
4533 /* Note: we check for a NULL image pointer here, _after_ we allocated
4534 * memory for the texture. That's what the GL spec calls for.
4539 GLint dstRowStride
= texture_row_stride(texImage
);
4540 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4541 texImage
->TexFormat
,
4543 0, 0, 0, /* dstX/Y/Zoffset */
4545 texImage
->ImageOffsets
,
4546 width
, height
, depth
,
4547 format
, type
, pixels
, packing
);
4549 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4553 _mesa_unmap_teximage_pbo(ctx
, packing
);
4560 * This is the software fallback for Driver.TexSubImage1D()
4561 * and Driver.CopyTexSubImage1D().
4564 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4565 GLint xoffset
, GLint width
,
4566 GLenum format
, GLenum type
, const void *pixels
,
4567 const struct gl_pixelstore_attrib
*packing
,
4568 struct gl_texture_object
*texObj
,
4569 struct gl_texture_image
*texImage
)
4571 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4572 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4573 pixels
, packing
, "glTexSubImage1D");
4578 const GLint dstRowStride
= 0;
4579 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4580 texImage
->TexFormat
,
4582 xoffset
, 0, 0, /* offsets */
4584 texImage
->ImageOffsets
,
4586 format
, type
, pixels
, packing
);
4588 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4592 _mesa_unmap_teximage_pbo(ctx
, packing
);
4598 * This is the software fallback for Driver.TexSubImage2D()
4599 * and Driver.CopyTexSubImage2D().
4602 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4603 GLint xoffset
, GLint yoffset
,
4604 GLint width
, GLint height
,
4605 GLenum format
, GLenum type
, const void *pixels
,
4606 const struct gl_pixelstore_attrib
*packing
,
4607 struct gl_texture_object
*texObj
,
4608 struct gl_texture_image
*texImage
)
4610 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4611 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4612 pixels
, packing
, "glTexSubImage2D");
4617 GLint dstRowStride
= texture_row_stride(texImage
);
4618 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4619 texImage
->TexFormat
,
4621 xoffset
, yoffset
, 0,
4623 texImage
->ImageOffsets
,
4625 format
, type
, pixels
, packing
);
4627 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4631 _mesa_unmap_teximage_pbo(ctx
, packing
);
4636 * This is the software fallback for Driver.TexSubImage3D().
4637 * and Driver.CopyTexSubImage3D().
4640 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4641 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4642 GLint width
, GLint height
, GLint depth
,
4643 GLenum format
, GLenum type
, const void *pixels
,
4644 const struct gl_pixelstore_attrib
*packing
,
4645 struct gl_texture_object
*texObj
,
4646 struct gl_texture_image
*texImage
)
4648 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4649 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4650 type
, pixels
, packing
,
4656 GLint dstRowStride
= texture_row_stride(texImage
);
4657 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4658 texImage
->TexFormat
,
4660 xoffset
, yoffset
, zoffset
,
4662 texImage
->ImageOffsets
,
4663 width
, height
, depth
,
4664 format
, type
, pixels
, packing
);
4666 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4670 _mesa_unmap_teximage_pbo(ctx
, packing
);
4675 * Fallback for Driver.CompressedTexImage1D()
4678 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4679 GLenum target
, GLint level
,
4680 GLint internalFormat
,
4681 GLint width
, GLint border
,
4682 GLsizei imageSize
, const GLvoid
*data
,
4683 struct gl_texture_object
*texObj
,
4684 struct gl_texture_image
*texImage
)
4686 /* this space intentionally left blank */
4688 (void) target
; (void) level
;
4689 (void) internalFormat
;
4690 (void) width
; (void) border
;
4691 (void) imageSize
; (void) data
;
4699 * Fallback for Driver.CompressedTexImage2D()
4702 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4703 GLenum target
, GLint level
,
4704 GLint internalFormat
,
4705 GLint width
, GLint height
, GLint border
,
4706 GLsizei imageSize
, const GLvoid
*data
,
4707 struct gl_texture_object
*texObj
,
4708 struct gl_texture_image
*texImage
)
4710 (void) width
; (void) height
; (void) border
;
4712 /* This is pretty simple, basically just do a memcpy without worrying
4713 * about the usual image unpacking or image transfer operations.
4717 ASSERT(texImage
->Width
> 0);
4718 ASSERT(texImage
->Height
> 0);
4719 ASSERT(texImage
->Depth
== 1);
4720 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4722 /* allocate storage */
4723 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4724 if (!texImage
->Data
) {
4725 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4729 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4731 "glCompressedTexImage2D");
4736 memcpy(texImage
->Data
, data
, imageSize
);
4738 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4744 * Fallback for Driver.CompressedTexImage3D()
4747 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4748 GLenum target
, GLint level
,
4749 GLint internalFormat
,
4750 GLint width
, GLint height
, GLint depth
,
4752 GLsizei imageSize
, const GLvoid
*data
,
4753 struct gl_texture_object
*texObj
,
4754 struct gl_texture_image
*texImage
)
4756 /* this space intentionally left blank */
4758 (void) target
; (void) level
;
4759 (void) internalFormat
;
4760 (void) width
; (void) height
; (void) depth
;
4762 (void) imageSize
; (void) data
;
4770 * Fallback for Driver.CompressedTexSubImage1D()
4773 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4775 GLint xoffset
, GLsizei width
,
4777 GLsizei imageSize
, const GLvoid
*data
,
4778 struct gl_texture_object
*texObj
,
4779 struct gl_texture_image
*texImage
)
4781 /* there are no compressed 1D texture formats yet */
4783 (void) target
; (void) level
;
4784 (void) xoffset
; (void) width
;
4786 (void) imageSize
; (void) data
;
4793 * Fallback for Driver.CompressedTexSubImage2D()
4796 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4798 GLint xoffset
, GLint yoffset
,
4799 GLsizei width
, GLsizei height
,
4801 GLsizei imageSize
, const GLvoid
*data
,
4802 struct gl_texture_object
*texObj
,
4803 struct gl_texture_image
*texImage
)
4805 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4809 const gl_format texFormat
= texImage
->TexFormat
;
4810 const GLint destWidth
= texImage
->Width
;
4813 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4818 /* these should have been caught sooner */
4819 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4820 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4821 ASSERT((xoffset
% bw
) == 0);
4822 ASSERT((yoffset
% bh
) == 0);
4824 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4825 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4827 "glCompressedTexSubImage2D");
4831 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4832 src
= (const GLubyte
*) data
;
4834 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4835 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4836 texFormat
, destWidth
,
4837 (GLubyte
*) texImage
->Data
);
4839 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4840 rows
= height
/ bh
; /* rows in blocks */
4842 /* copy rows of blocks */
4843 for (i
= 0; i
< rows
; i
++) {
4844 memcpy(dest
, src
, bytesPerRow
);
4845 dest
+= destRowStride
;
4846 src
+= srcRowStride
;
4849 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4854 * Fallback for Driver.CompressedTexSubImage3D()
4857 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4859 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4860 GLsizei width
, GLsizei height
, GLsizei depth
,
4862 GLsizei imageSize
, const GLvoid
*data
,
4863 struct gl_texture_object
*texObj
,
4864 struct gl_texture_image
*texImage
)
4866 /* there are no compressed 3D texture formats yet */
4868 (void) target
; (void) level
;
4869 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4870 (void) width
; (void) height
; (void) depth
;
4872 (void) imageSize
; (void) data
;