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, convolution!, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
64 #include "texcompress.h"
65 #include "texcompress_fxt1.h"
66 #include "texcompress_s3tc.h"
79 * Texture image storage function.
81 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
85 * Return GL_TRUE if the given image format is one that be converted
86 * to another format by swizzling.
89 can_swizzle(GLenum logicalBaseFormat
)
91 switch (logicalBaseFormat
) {
94 case GL_LUMINANCE_ALPHA
:
128 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
129 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
130 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
131 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
134 static const struct {
137 GLubyte from_rgba
[6];
138 } mappings
[MAX_IDX
] =
148 MAP4(ZERO
, ZERO
, ZERO
, 0),
179 MAP4(0, ZERO
, ZERO
, ONE
),
185 MAP4(ZERO
, 0, ZERO
, ONE
),
191 MAP4(ZERO
, ZERO
, 0, ONE
),
217 * Convert a GL image format enum to an IDX_* value (see above).
220 get_map_idx(GLenum value
)
223 case GL_LUMINANCE
: return IDX_LUMINANCE
;
224 case GL_ALPHA
: return IDX_ALPHA
;
225 case GL_INTENSITY
: return IDX_INTENSITY
;
226 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
227 case GL_RGB
: return IDX_RGB
;
228 case GL_RGBA
: return IDX_RGBA
;
229 case GL_RED
: return IDX_RED
;
230 case GL_GREEN
: return IDX_GREEN
;
231 case GL_BLUE
: return IDX_BLUE
;
232 case GL_BGR
: return IDX_BGR
;
233 case GL_BGRA
: return IDX_BGRA
;
234 case GL_ABGR_EXT
: return IDX_ABGR
;
236 _mesa_problem(NULL
, "Unexpected inFormat");
243 * When promoting texture formats (see below) we need to compute the
244 * mapping of dest components back to source components.
245 * This function does that.
246 * \param inFormat the incoming format of the texture
247 * \param outFormat the final texture format
248 * \return map[6] a full 6-component map
251 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
254 const int inFmt
= get_map_idx(inFormat
);
255 const int outFmt
= get_map_idx(outFormat
);
256 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
257 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
260 for (i
= 0; i
< 4; i
++)
261 map
[i
] = in2rgba
[rgba2out
[i
]];
267 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
268 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
269 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
281 * Make a temporary (color) texture image with GLfloat components.
282 * Apply all needed pixel unpacking and pixel transfer operations.
283 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
284 * Suppose the user specifies GL_LUMINANCE as the internal texture format
285 * but the graphics hardware doesn't support luminance textures. So, might
286 * use an RGB hardware format instead.
287 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
289 * \param ctx the rendering context
290 * \param dims image dimensions: 1, 2 or 3
291 * \param logicalBaseFormat basic texture derived from the user's
292 * internal texture format value
293 * \param textureBaseFormat the actual basic format of the texture
294 * \param srcWidth source image width
295 * \param srcHeight source image height
296 * \param srcDepth source image depth
297 * \param srcFormat source image format
298 * \param srcType source image type
299 * \param srcAddr source image address
300 * \param srcPacking source image pixel packing
301 * \return resulting image with format = textureBaseFormat and type = GLfloat.
304 make_temp_float_image(GLcontext
*ctx
, GLuint dims
,
305 GLenum logicalBaseFormat
,
306 GLenum textureBaseFormat
,
307 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
308 GLenum srcFormat
, GLenum srcType
,
309 const GLvoid
*srcAddr
,
310 const struct gl_pixelstore_attrib
*srcPacking
)
312 GLuint transferOps
= ctx
->_ImageTransferState
;
315 ASSERT(dims
>= 1 && dims
<= 3);
317 ASSERT(logicalBaseFormat
== GL_RGBA
||
318 logicalBaseFormat
== GL_RGB
||
319 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
320 logicalBaseFormat
== GL_LUMINANCE
||
321 logicalBaseFormat
== GL_ALPHA
||
322 logicalBaseFormat
== GL_INTENSITY
||
323 logicalBaseFormat
== GL_COLOR_INDEX
||
324 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
326 ASSERT(textureBaseFormat
== GL_RGBA
||
327 textureBaseFormat
== GL_RGB
||
328 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
329 textureBaseFormat
== GL_LUMINANCE
||
330 textureBaseFormat
== GL_ALPHA
||
331 textureBaseFormat
== GL_INTENSITY
||
332 textureBaseFormat
== GL_COLOR_INDEX
||
333 textureBaseFormat
== GL_DEPTH_COMPONENT
);
335 /* conventional color image */
337 if ((dims
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
338 (dims
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
339 (dims
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
340 /* need image convolution */
341 const GLuint preConvTransferOps
342 = (transferOps
& IMAGE_PRE_CONVOLUTION_BITS
) | IMAGE_CLAMP_BIT
;
343 const GLuint postConvTransferOps
344 = (transferOps
& IMAGE_POST_CONVOLUTION_BITS
) | IMAGE_CLAMP_BIT
;
346 GLint convWidth
= srcWidth
, convHeight
= srcHeight
;
349 /* pre-convolution image buffer (3D) */
350 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
351 * 4 * sizeof(GLfloat
));
355 /* post-convolution image buffer (2D) */
356 convImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
357 * 4 * sizeof(GLfloat
));
363 /* loop over 3D image slices */
364 for (img
= 0; img
< srcDepth
; img
++) {
365 GLfloat
*dst
= tempImage
+ img
* (srcWidth
* srcHeight
* 4);
367 /* unpack and do transfer ops up to convolution */
368 for (row
= 0; row
< srcHeight
; row
++) {
369 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
370 srcAddr
, srcWidth
, srcHeight
,
371 srcFormat
, srcType
, img
, row
, 0);
372 _mesa_unpack_color_span_float(ctx
, srcWidth
, GL_RGBA
, dst
,
373 srcFormat
, srcType
, src
,
379 /* size after optional convolution */
380 convWidth
= srcWidth
;
381 convHeight
= srcHeight
;
386 GLfloat
*src
= tempImage
+ img
* (srcWidth
* srcHeight
* 4);
388 ASSERT(ctx
->Pixel
.Convolution1DEnabled
);
389 _mesa_convolve_1d_image(ctx
, &convWidth
, src
, convImage
);
392 if (ctx
->Pixel
.Convolution2DEnabled
) {
393 _mesa_convolve_2d_image(ctx
, &convWidth
, &convHeight
,
397 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
398 _mesa_convolve_sep_image(ctx
, &convWidth
, &convHeight
,
404 /* do post-convolution transfer and pack into tempImage */
406 const GLint logComponents
407 = _mesa_components_in_format(logicalBaseFormat
);
408 const GLfloat
*src
= convImage
;
409 GLfloat
*dst
= tempImage
+ img
* (convWidth
* convHeight
* 4);
410 for (row
= 0; row
< convHeight
; row
++) {
411 _mesa_pack_rgba_span_float(ctx
, convWidth
,
412 (GLfloat (*)[4]) src
,
413 logicalBaseFormat
, GL_FLOAT
,
414 dst
, &ctx
->DefaultPacking
,
415 postConvTransferOps
);
416 src
+= convWidth
* 4;
417 dst
+= convWidth
* logComponents
;
420 } /* loop over 3D image slices */
424 /* might need these below */
425 srcWidth
= convWidth
;
426 srcHeight
= convHeight
;
430 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
431 const GLint srcStride
=
432 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
436 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
437 * components
* sizeof(GLfloat
));
442 for (img
= 0; img
< srcDepth
; img
++) {
444 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
448 for (row
= 0; row
< srcHeight
; row
++) {
449 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
450 dst
, srcFormat
, srcType
, src
,
451 srcPacking
, transferOps
);
452 dst
+= srcWidth
* components
;
458 if (logicalBaseFormat
!= textureBaseFormat
) {
460 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
461 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
466 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
467 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
468 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
470 /* The actual texture format should have at least as many components
471 * as the logical texture format.
473 ASSERT(texComponents
>= logComponents
);
475 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
476 * texComponents
* sizeof(GLfloat
));
482 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
484 n
= srcWidth
* srcHeight
* srcDepth
;
485 for (i
= 0; i
< n
; i
++) {
487 for (k
= 0; k
< texComponents
; k
++) {
490 newImage
[i
* texComponents
+ k
] = 0.0F
;
492 newImage
[i
* texComponents
+ k
] = 1.0F
;
494 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
499 tempImage
= newImage
;
507 * Make a temporary (color) texture image with GLchan components.
508 * Apply all needed pixel unpacking and pixel transfer operations.
509 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
510 * Suppose the user specifies GL_LUMINANCE as the internal texture format
511 * but the graphics hardware doesn't support luminance textures. So, might
512 * use an RGB hardware format instead.
513 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
515 * \param ctx the rendering context
516 * \param dims image dimensions: 1, 2 or 3
517 * \param logicalBaseFormat basic texture derived from the user's
518 * internal texture format value
519 * \param textureBaseFormat the actual basic format of the texture
520 * \param srcWidth source image width
521 * \param srcHeight source image height
522 * \param srcDepth source image depth
523 * \param srcFormat source image format
524 * \param srcType source image type
525 * \param srcAddr source image address
526 * \param srcPacking source image pixel packing
527 * \return resulting image with format = textureBaseFormat and type = GLchan.
530 _mesa_make_temp_chan_image(GLcontext
*ctx
, GLuint dims
,
531 GLenum logicalBaseFormat
,
532 GLenum textureBaseFormat
,
533 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
534 GLenum srcFormat
, GLenum srcType
,
535 const GLvoid
*srcAddr
,
536 const struct gl_pixelstore_attrib
*srcPacking
)
538 GLuint transferOps
= ctx
->_ImageTransferState
;
539 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
540 GLboolean freeSrcImage
= GL_FALSE
;
542 GLchan
*tempImage
, *dst
;
544 ASSERT(dims
>= 1 && dims
<= 3);
546 ASSERT(logicalBaseFormat
== GL_RGBA
||
547 logicalBaseFormat
== GL_RGB
||
548 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
549 logicalBaseFormat
== GL_LUMINANCE
||
550 logicalBaseFormat
== GL_ALPHA
||
551 logicalBaseFormat
== GL_INTENSITY
);
553 ASSERT(textureBaseFormat
== GL_RGBA
||
554 textureBaseFormat
== GL_RGB
||
555 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
556 textureBaseFormat
== GL_LUMINANCE
||
557 textureBaseFormat
== GL_ALPHA
||
558 textureBaseFormat
== GL_INTENSITY
);
561 if ((dims
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
562 (dims
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
563 (dims
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
564 /* get convolved image */
565 GLfloat
*convImage
= make_temp_float_image(ctx
, dims
,
568 srcWidth
, srcHeight
, srcDepth
,
570 srcAddr
, srcPacking
);
573 /* the convolved image is our new source image */
575 srcFormat
= logicalBaseFormat
;
577 srcPacking
= &ctx
->DefaultPacking
;
578 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
580 freeSrcImage
= GL_TRUE
;
584 /* unpack and transfer the source image */
585 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
586 * components
* sizeof(GLchan
));
589 free((void *) srcAddr
);
595 for (img
= 0; img
< srcDepth
; img
++) {
596 const GLint srcStride
=
597 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
599 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
603 for (row
= 0; row
< srcHeight
; row
++) {
604 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
605 srcFormat
, srcType
, src
, srcPacking
,
607 dst
+= srcWidth
* components
;
612 /* If we made a temporary image for convolution, free it here */
614 free((void *) srcAddr
);
617 if (logicalBaseFormat
!= textureBaseFormat
) {
618 /* one more conversion step */
619 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
620 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
625 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
626 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
627 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
629 /* The actual texture format should have at least as many components
630 * as the logical texture format.
632 ASSERT(texComponents
>= logComponents
);
634 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
635 * texComponents
* sizeof(GLchan
));
641 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
643 n
= srcWidth
* srcHeight
* srcDepth
;
644 for (i
= 0; i
< n
; i
++) {
646 for (k
= 0; k
< texComponents
; k
++) {
649 newImage
[i
* texComponents
+ k
] = 0;
651 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
653 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
658 tempImage
= newImage
;
666 * Copy GLubyte pixels from <src> to <dst> with swizzling.
667 * \param dst destination pixels
668 * \param dstComponents number of color components in destination pixels
669 * \param src source pixels
670 * \param srcComponents number of color components in source pixels
671 * \param map the swizzle mapping. map[X] says where to find the X component
672 * in the source image's pixels. For example, if the source image
673 * is GL_BGRA and X = red, map[0] yields 2.
674 * \param count number of pixels to copy/swizzle.
677 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
678 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
680 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
683 for (i = 0; i < count; i++) { \
685 if (srcComps == 4) { \
686 COPY_4UBV(tmp, src); \
689 for (j = 0; j < srcComps; j++) { \
694 for (j = 0; j < dstComps; j++) { \
695 dst[j] = tmp[map[j]]; \
706 ASSERT(srcComponents
<= 4);
707 ASSERT(dstComponents
<= 4);
709 switch (dstComponents
) {
711 switch (srcComponents
) {
713 SWZ_CPY(dst
, src
, count
, 4, 4);
716 SWZ_CPY(dst
, src
, count
, 4, 3);
719 SWZ_CPY(dst
, src
, count
, 4, 2);
722 SWZ_CPY(dst
, src
, count
, 4, 1);
729 switch (srcComponents
) {
731 SWZ_CPY(dst
, src
, count
, 3, 4);
734 SWZ_CPY(dst
, src
, count
, 3, 3);
737 SWZ_CPY(dst
, src
, count
, 3, 2);
740 SWZ_CPY(dst
, src
, count
, 3, 1);
747 switch (srcComponents
) {
749 SWZ_CPY(dst
, src
, count
, 2, 4);
752 SWZ_CPY(dst
, src
, count
, 2, 3);
755 SWZ_CPY(dst
, src
, count
, 2, 2);
758 SWZ_CPY(dst
, src
, count
, 2, 1);
765 switch (srcComponents
) {
767 SWZ_CPY(dst
, src
, count
, 1, 4);
770 SWZ_CPY(dst
, src
, count
, 1, 3);
773 SWZ_CPY(dst
, src
, count
, 1, 2);
776 SWZ_CPY(dst
, src
, count
, 1, 1);
790 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
791 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
793 /* Deal with the _REV input types:
795 static const GLubyte
*
796 type_mapping( GLenum srcType
)
800 case GL_UNSIGNED_BYTE
:
802 case GL_UNSIGNED_INT_8_8_8_8
:
803 return _mesa_little_endian() ? map_3210
: map_identity
;
804 case GL_UNSIGNED_INT_8_8_8_8_REV
:
805 return _mesa_little_endian() ? map_identity
: map_3210
;
811 /* Mapping required if input type is
813 static const GLubyte
*
814 byteswap_mapping( GLboolean swapBytes
,
822 case GL_UNSIGNED_BYTE
:
824 case GL_UNSIGNED_INT_8_8_8_8
:
825 case GL_UNSIGNED_INT_8_8_8_8_REV
:
835 * Transfer a GLubyte texture image with component swizzling.
838 _mesa_swizzle_ubyte_image(GLcontext
*ctx
,
843 GLenum baseInternalFormat
,
845 const GLubyte
*rgba2dst
,
846 GLuint dstComponents
,
849 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
851 const GLuint
*dstImageOffsets
,
853 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
854 const GLvoid
*srcAddr
,
855 const struct gl_pixelstore_attrib
*srcPacking
)
857 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
858 const GLubyte
*srctype2ubyte
, *swap
;
859 GLubyte map
[4], src2base
[6], base2rgba
[6];
861 const GLint srcRowStride
=
862 _mesa_image_row_stride(srcPacking
, srcWidth
,
863 srcFormat
, GL_UNSIGNED_BYTE
);
864 const GLint srcImageStride
865 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
867 const GLubyte
*srcImage
868 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
869 srcWidth
, srcHeight
, srcFormat
,
870 GL_UNSIGNED_BYTE
, 0, 0, 0);
874 /* Translate from src->baseInternal->GL_RGBA->dst. This will
875 * correctly deal with RGBA->RGB->RGBA conversions where the final
876 * A value must be 0xff regardless of the incoming alpha values.
878 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
879 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
880 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
881 srctype2ubyte
= type_mapping(srcType
);
884 for (i
= 0; i
< 4; i
++)
885 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
887 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
889 if (srcComponents
== dstComponents
&&
890 srcRowStride
== dstRowStride
&&
891 srcRowStride
== srcWidth
* srcComponents
&&
893 /* 1 and 2D images only */
894 GLubyte
*dstImage
= (GLubyte
*) dstAddr
895 + dstYoffset
* dstRowStride
896 + dstXoffset
* dstComponents
;
897 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
898 srcWidth
* srcHeight
);
902 for (img
= 0; img
< srcDepth
; img
++) {
903 const GLubyte
*srcRow
= srcImage
;
904 GLubyte
*dstRow
= (GLubyte
*) dstAddr
905 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
906 + dstYoffset
* dstRowStride
907 + dstXoffset
* dstComponents
;
908 for (row
= 0; row
< srcHeight
; row
++) {
909 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
910 dstRow
+= dstRowStride
;
911 srcRow
+= srcRowStride
;
913 srcImage
+= srcImageStride
;
920 * Teximage storage routine for when a simple memcpy will do.
921 * No pixel transfer operations or special texel encodings allowed.
922 * 1D, 2D and 3D images supported.
925 memcpy_texture(GLcontext
*ctx
,
929 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
931 const GLuint
*dstImageOffsets
,
932 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
933 GLenum srcFormat
, GLenum srcType
,
934 const GLvoid
*srcAddr
,
935 const struct gl_pixelstore_attrib
*srcPacking
)
937 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
939 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
940 srcWidth
, srcHeight
, srcFormat
, srcType
);
941 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
942 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
943 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
944 const GLint bytesPerRow
= srcWidth
* texelBytes
;
947 /* XXX update/re-enable for dstImageOffsets array */
948 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
949 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
950 GLubyte
*dstImage
= (GLubyte
*) dstAddr
951 + dstZoffset
* dstImageStride
952 + dstYoffset
* dstRowStride
953 + dstXoffset
* texelBytes
;
955 if (dstRowStride
== srcRowStride
&&
956 dstRowStride
== bytesPerRow
&&
957 ((dstImageStride
== srcImageStride
&&
958 dstImageStride
== bytesPerImage
) ||
961 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
966 for (img
= 0; img
< srcDepth
; img
++) {
967 const GLubyte
*srcRow
= srcImage
;
968 GLubyte
*dstRow
= dstImage
;
969 for (row
= 0; row
< srcHeight
; row
++) {
970 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
971 dstRow
+= dstRowStride
;
972 srcRow
+= srcRowStride
;
974 srcImage
+= srcImageStride
;
975 dstImage
+= dstImageStride
;
981 for (img
= 0; img
< srcDepth
; img
++) {
982 const GLubyte
*srcRow
= srcImage
;
983 GLubyte
*dstRow
= (GLubyte
*) dstAddr
984 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
985 + dstYoffset
* dstRowStride
986 + dstXoffset
* texelBytes
;
987 for (row
= 0; row
< srcHeight
; row
++) {
988 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
989 dstRow
+= dstRowStride
;
990 srcRow
+= srcRowStride
;
992 srcImage
+= srcImageStride
;
999 * Store a 32-bit integer depth component texture image.
1002 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1004 const GLuint depthScale
= 0xffffffff;
1005 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1007 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1008 ASSERT(texelBytes
== sizeof(GLuint
));
1010 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1011 ctx
->Pixel
.DepthBias
== 0.0f
&&
1012 !srcPacking
->SwapBytes
&&
1013 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1014 srcFormat
== GL_DEPTH_COMPONENT
&&
1015 srcType
== GL_UNSIGNED_INT
) {
1016 /* simple memcpy path */
1017 memcpy_texture(ctx
, dims
,
1018 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1021 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1022 srcAddr
, srcPacking
);
1027 for (img
= 0; img
< srcDepth
; img
++) {
1028 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1029 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1030 + dstYoffset
* dstRowStride
1031 + dstXoffset
* texelBytes
;
1032 for (row
= 0; row
< srcHeight
; row
++) {
1033 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1034 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1035 _mesa_unpack_depth_span(ctx
, srcWidth
,
1036 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1037 depthScale
, srcType
, src
, srcPacking
);
1038 dstRow
+= dstRowStride
;
1047 * Store a 24-bit integer depth component texture image.
1050 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1052 const GLuint depthScale
= 0xffffff;
1053 const GLuint texelBytes
= 4;
1056 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1061 for (img
= 0; img
< srcDepth
; img
++) {
1062 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1063 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1064 + dstYoffset
* dstRowStride
1065 + dstXoffset
* texelBytes
;
1066 for (row
= 0; row
< srcHeight
; row
++) {
1067 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1068 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1069 _mesa_unpack_depth_span(ctx
, srcWidth
,
1070 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1071 depthScale
, srcType
, src
, srcPacking
);
1072 dstRow
+= dstRowStride
;
1081 * Store a 24-bit integer depth component texture image.
1084 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1086 const GLuint depthScale
= 0xffffff;
1087 const GLuint texelBytes
= 4;
1090 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1095 for (img
= 0; img
< srcDepth
; img
++) {
1096 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1097 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1098 + dstYoffset
* dstRowStride
1099 + dstXoffset
* texelBytes
;
1100 for (row
= 0; row
< srcHeight
; row
++) {
1101 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1102 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1103 GLuint
*dst
= (GLuint
*) dstRow
;
1105 _mesa_unpack_depth_span(ctx
, srcWidth
,
1106 GL_UNSIGNED_INT
, dst
,
1107 depthScale
, srcType
, src
, srcPacking
);
1108 for (i
= 0; i
< srcWidth
; i
++)
1110 dstRow
+= dstRowStride
;
1119 * Store a 16-bit integer depth component texture image.
1122 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1124 const GLuint depthScale
= 0xffff;
1125 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1127 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1128 ASSERT(texelBytes
== sizeof(GLushort
));
1130 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1131 ctx
->Pixel
.DepthBias
== 0.0f
&&
1132 !srcPacking
->SwapBytes
&&
1133 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1134 srcFormat
== GL_DEPTH_COMPONENT
&&
1135 srcType
== GL_UNSIGNED_SHORT
) {
1136 /* simple memcpy path */
1137 memcpy_texture(ctx
, dims
,
1138 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1141 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1142 srcAddr
, srcPacking
);
1147 for (img
= 0; img
< srcDepth
; img
++) {
1148 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1149 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1150 + dstYoffset
* dstRowStride
1151 + dstXoffset
* texelBytes
;
1152 for (row
= 0; row
< srcHeight
; row
++) {
1153 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1154 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1155 GLushort
*dst16
= (GLushort
*) dstRow
;
1156 _mesa_unpack_depth_span(ctx
, srcWidth
,
1157 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1158 srcType
, src
, srcPacking
);
1159 dstRow
+= dstRowStride
;
1168 * Store an rgb565 or rgb565_rev texture image.
1171 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1173 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1174 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1176 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1177 dstFormat
== MESA_FORMAT_RGB565_REV
);
1178 ASSERT(texelBytes
== 2);
1180 if (!ctx
->_ImageTransferState
&&
1181 !srcPacking
->SwapBytes
&&
1182 dstFormat
== MESA_FORMAT_RGB565
&&
1183 baseInternalFormat
== GL_RGB
&&
1184 srcFormat
== GL_RGB
&&
1185 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1186 /* simple memcpy path */
1187 memcpy_texture(ctx
, dims
,
1188 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1191 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1192 srcAddr
, srcPacking
);
1194 else if (!ctx
->_ImageTransferState
&&
1195 !srcPacking
->SwapBytes
&&
1196 baseInternalFormat
== GL_RGB
&&
1197 srcFormat
== GL_RGB
&&
1198 srcType
== GL_UNSIGNED_BYTE
&&
1200 /* do optimized tex store */
1201 const GLint srcRowStride
=
1202 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1203 const GLubyte
*src
= (const GLubyte
*)
1204 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1205 srcFormat
, srcType
, 0, 0, 0);
1206 GLubyte
*dst
= (GLubyte
*) dstAddr
1207 + dstYoffset
* dstRowStride
1208 + dstXoffset
* texelBytes
;
1210 for (row
= 0; row
< srcHeight
; row
++) {
1211 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1212 GLushort
*dstUS
= (GLushort
*) dst
;
1213 /* check for byteswapped format */
1214 if (dstFormat
== MESA_FORMAT_RGB565
) {
1215 for (col
= 0; col
< srcWidth
; col
++) {
1216 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1221 for (col
= 0; col
< srcWidth
; col
++) {
1222 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1226 dst
+= dstRowStride
;
1227 src
+= srcRowStride
;
1232 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1235 srcWidth
, srcHeight
, srcDepth
,
1236 srcFormat
, srcType
, srcAddr
,
1238 const GLchan
*src
= tempImage
;
1239 GLint img
, row
, col
;
1242 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1243 for (img
= 0; img
< srcDepth
; img
++) {
1244 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1245 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1246 + dstYoffset
* dstRowStride
1247 + dstXoffset
* texelBytes
;
1248 for (row
= 0; row
< srcHeight
; row
++) {
1249 GLushort
*dstUS
= (GLushort
*) dstRow
;
1250 /* check for byteswapped format */
1251 if (dstFormat
== MESA_FORMAT_RGB565
) {
1252 for (col
= 0; col
< srcWidth
; col
++) {
1253 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1254 CHAN_TO_UBYTE(src
[GCOMP
]),
1255 CHAN_TO_UBYTE(src
[BCOMP
]) );
1260 for (col
= 0; col
< srcWidth
; col
++) {
1261 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1262 CHAN_TO_UBYTE(src
[GCOMP
]),
1263 CHAN_TO_UBYTE(src
[BCOMP
]) );
1267 dstRow
+= dstRowStride
;
1270 free((void *) tempImage
);
1277 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1280 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1282 const GLboolean littleEndian
= _mesa_little_endian();
1283 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1284 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1286 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1287 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1288 ASSERT(texelBytes
== 4);
1290 if (!ctx
->_ImageTransferState
&&
1291 !srcPacking
->SwapBytes
&&
1292 dstFormat
== MESA_FORMAT_RGBA8888
&&
1293 baseInternalFormat
== GL_RGBA
&&
1294 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1295 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1296 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1297 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1298 /* simple memcpy path */
1299 memcpy_texture(ctx
, dims
,
1300 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1303 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1304 srcAddr
, srcPacking
);
1306 else if (!ctx
->_ImageTransferState
&&
1307 !srcPacking
->SwapBytes
&&
1308 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1309 baseInternalFormat
== GL_RGBA
&&
1310 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1311 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1312 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1313 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1314 /* simple memcpy path */
1315 memcpy_texture(ctx
, dims
,
1316 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1319 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1320 srcAddr
, srcPacking
);
1322 else if (!ctx
->_ImageTransferState
&&
1323 (srcType
== GL_UNSIGNED_BYTE
||
1324 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1325 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1326 can_swizzle(baseInternalFormat
) &&
1327 can_swizzle(srcFormat
)) {
1331 /* dstmap - how to swizzle from RGBA to dst format:
1333 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1334 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1347 _mesa_swizzle_ubyte_image(ctx
, dims
,
1352 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1353 dstRowStride
, dstImageOffsets
,
1354 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1359 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1362 srcWidth
, srcHeight
, srcDepth
,
1363 srcFormat
, srcType
, srcAddr
,
1365 const GLchan
*src
= tempImage
;
1366 GLint img
, row
, col
;
1369 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1370 for (img
= 0; img
< srcDepth
; img
++) {
1371 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1372 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1373 + dstYoffset
* dstRowStride
1374 + dstXoffset
* texelBytes
;
1375 for (row
= 0; row
< srcHeight
; row
++) {
1376 GLuint
*dstUI
= (GLuint
*) dstRow
;
1377 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1378 for (col
= 0; col
< srcWidth
; col
++) {
1379 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1380 CHAN_TO_UBYTE(src
[GCOMP
]),
1381 CHAN_TO_UBYTE(src
[BCOMP
]),
1382 CHAN_TO_UBYTE(src
[ACOMP
]) );
1387 for (col
= 0; col
< srcWidth
; col
++) {
1388 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1389 CHAN_TO_UBYTE(src
[GCOMP
]),
1390 CHAN_TO_UBYTE(src
[BCOMP
]),
1391 CHAN_TO_UBYTE(src
[ACOMP
]) );
1395 dstRow
+= dstRowStride
;
1398 free((void *) tempImage
);
1405 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1407 const GLboolean littleEndian
= _mesa_little_endian();
1408 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1409 const GLenum baseFormat
= GL_RGBA
;
1411 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1412 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1413 dstFormat
== MESA_FORMAT_XRGB8888
||
1414 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1415 ASSERT(texelBytes
== 4);
1417 if (!ctx
->_ImageTransferState
&&
1418 !srcPacking
->SwapBytes
&&
1419 (dstFormat
== MESA_FORMAT_ARGB8888
||
1420 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1421 baseInternalFormat
== GL_RGBA
&&
1422 srcFormat
== GL_BGRA
&&
1423 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1424 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1425 /* simple memcpy path (little endian) */
1426 memcpy_texture(ctx
, dims
,
1427 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1430 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1431 srcAddr
, srcPacking
);
1433 else if (!ctx
->_ImageTransferState
&&
1434 !srcPacking
->SwapBytes
&&
1435 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1436 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1437 baseInternalFormat
== GL_RGBA
&&
1438 srcFormat
== GL_BGRA
&&
1439 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1440 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1441 /* simple memcpy path (big endian) */
1442 memcpy_texture(ctx
, dims
,
1443 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1446 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1447 srcAddr
, srcPacking
);
1449 else if (!ctx
->_ImageTransferState
&&
1450 !srcPacking
->SwapBytes
&&
1451 (dstFormat
== MESA_FORMAT_ARGB8888
||
1452 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1453 srcFormat
== GL_RGB
&&
1454 (baseInternalFormat
== GL_RGBA
||
1455 baseInternalFormat
== GL_RGB
) &&
1456 srcType
== GL_UNSIGNED_BYTE
) {
1458 for (img
= 0; img
< srcDepth
; img
++) {
1459 const GLint srcRowStride
=
1460 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1461 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1462 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1463 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1464 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1465 + dstYoffset
* dstRowStride
1466 + dstXoffset
* texelBytes
;
1467 for (row
= 0; row
< srcHeight
; row
++) {
1468 GLuint
*d4
= (GLuint
*) dstRow
;
1469 for (col
= 0; col
< srcWidth
; col
++) {
1470 d4
[col
] = PACK_COLOR_8888(0xff,
1471 srcRow
[col
* 3 + RCOMP
],
1472 srcRow
[col
* 3 + GCOMP
],
1473 srcRow
[col
* 3 + BCOMP
]);
1475 dstRow
+= dstRowStride
;
1476 srcRow
+= srcRowStride
;
1480 else if (!ctx
->_ImageTransferState
&&
1481 !srcPacking
->SwapBytes
&&
1482 dstFormat
== MESA_FORMAT_ARGB8888
&&
1483 srcFormat
== GL_RGBA
&&
1484 baseInternalFormat
== GL_RGBA
&&
1485 srcType
== GL_UNSIGNED_BYTE
) {
1486 /* same as above case, but src data has alpha too */
1487 GLint img
, row
, col
;
1488 /* For some reason, streaming copies to write-combined regions
1489 * are extremely sensitive to the characteristics of how the
1490 * source data is retrieved. By reordering the source reads to
1491 * be in-order, the speed of this operation increases by half.
1492 * Strangely the same isn't required for the RGB path, above.
1494 for (img
= 0; img
< srcDepth
; img
++) {
1495 const GLint srcRowStride
=
1496 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1497 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1498 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1499 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1500 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1501 + dstYoffset
* dstRowStride
1502 + dstXoffset
* texelBytes
;
1503 for (row
= 0; row
< srcHeight
; row
++) {
1504 GLuint
*d4
= (GLuint
*) dstRow
;
1505 for (col
= 0; col
< srcWidth
; col
++) {
1506 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1507 srcRow
[col
* 4 + RCOMP
],
1508 srcRow
[col
* 4 + GCOMP
],
1509 srcRow
[col
* 4 + BCOMP
]);
1511 dstRow
+= dstRowStride
;
1512 srcRow
+= srcRowStride
;
1516 else if (!ctx
->_ImageTransferState
&&
1517 (srcType
== GL_UNSIGNED_BYTE
||
1518 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1519 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1520 can_swizzle(baseInternalFormat
) &&
1521 can_swizzle(srcFormat
)) {
1525 /* dstmap - how to swizzle from RGBA to dst format:
1527 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1528 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1529 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1530 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1531 dstmap
[3] = 3; /* alpha */
1532 dstmap
[2] = 0; /* red */
1533 dstmap
[1] = 1; /* green */
1534 dstmap
[0] = 2; /* blue */
1537 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1538 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1539 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1540 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1547 _mesa_swizzle_ubyte_image(ctx
, dims
,
1553 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1556 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1561 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1564 srcWidth
, srcHeight
, srcDepth
,
1565 srcFormat
, srcType
, srcAddr
,
1567 const GLchan
*src
= tempImage
;
1568 GLint img
, row
, col
;
1571 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
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 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1702 for (img
= 0; img
< srcDepth
; img
++) {
1703 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1704 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1705 + dstYoffset
* dstRowStride
1706 + dstXoffset
* texelBytes
;
1707 for (row
= 0; row
< srcHeight
; row
++) {
1710 for (col
= 0; col
< srcWidth
; col
++) {
1711 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1712 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1713 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1718 for (col
= 0; col
< srcWidth
; col
++) {
1719 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1720 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1721 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1726 for (col
= 0; col
< srcWidth
; col
++) {
1727 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1728 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1729 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1733 dstRow
+= dstRowStride
;
1736 free((void *) tempImage
);
1743 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1745 const GLboolean littleEndian
= _mesa_little_endian();
1746 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1747 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1749 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1750 ASSERT(texelBytes
== 3);
1752 if (!ctx
->_ImageTransferState
&&
1753 !srcPacking
->SwapBytes
&&
1754 baseInternalFormat
== GL_RGB
&&
1755 srcFormat
== GL_RGB
&&
1756 srcType
== GL_UNSIGNED_BYTE
&&
1758 /* simple memcpy path */
1759 memcpy_texture(ctx
, dims
,
1760 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1763 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1764 srcAddr
, srcPacking
);
1766 else if (!ctx
->_ImageTransferState
&&
1767 !srcPacking
->SwapBytes
&&
1768 srcFormat
== GL_RGBA
&&
1769 srcType
== GL_UNSIGNED_BYTE
) {
1770 /* extract BGR from RGBA */
1772 for (img
= 0; img
< srcDepth
; img
++) {
1773 const GLint srcRowStride
=
1774 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1775 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1776 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1777 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1778 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1779 + dstYoffset
* dstRowStride
1780 + dstXoffset
* texelBytes
;
1781 for (row
= 0; row
< srcHeight
; row
++) {
1782 for (col
= 0; col
< srcWidth
; col
++) {
1783 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1784 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1785 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1787 dstRow
+= dstRowStride
;
1788 srcRow
+= srcRowStride
;
1792 else if (!ctx
->_ImageTransferState
&&
1793 srcType
== GL_UNSIGNED_BYTE
&&
1794 can_swizzle(baseInternalFormat
) &&
1795 can_swizzle(srcFormat
)) {
1799 /* dstmap - how to swizzle from RGBA to dst format:
1804 dstmap
[3] = ONE
; /* ? */
1806 _mesa_swizzle_ubyte_image(ctx
, dims
,
1811 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1812 dstRowStride
, dstImageOffsets
,
1813 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1818 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1821 srcWidth
, srcHeight
, srcDepth
,
1822 srcFormat
, srcType
, srcAddr
,
1824 const GLchan
*src
= (const GLchan
*) tempImage
;
1825 GLint img
, row
, col
;
1828 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1829 for (img
= 0; img
< srcDepth
; img
++) {
1830 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1831 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1832 + dstYoffset
* dstRowStride
1833 + dstXoffset
* texelBytes
;
1834 for (row
= 0; row
< srcHeight
; row
++) {
1835 for (col
= 0; col
< srcWidth
; col
++) {
1836 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1837 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1838 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1841 dstRow
+= dstRowStride
;
1844 free((void *) tempImage
);
1851 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1853 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1854 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1856 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1857 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1858 ASSERT(texelBytes
== 2);
1860 if (!ctx
->_ImageTransferState
&&
1861 !srcPacking
->SwapBytes
&&
1862 dstFormat
== MESA_FORMAT_ARGB4444
&&
1863 baseInternalFormat
== GL_RGBA
&&
1864 srcFormat
== GL_BGRA
&&
1865 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1866 /* simple memcpy path */
1867 memcpy_texture(ctx
, dims
,
1868 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1871 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1872 srcAddr
, srcPacking
);
1876 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1879 srcWidth
, srcHeight
, srcDepth
,
1880 srcFormat
, srcType
, srcAddr
,
1882 const GLchan
*src
= tempImage
;
1883 GLint img
, row
, col
;
1886 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1887 for (img
= 0; img
< srcDepth
; img
++) {
1888 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1889 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1890 + dstYoffset
* dstRowStride
1891 + dstXoffset
* texelBytes
;
1892 for (row
= 0; row
< srcHeight
; row
++) {
1893 GLushort
*dstUS
= (GLushort
*) dstRow
;
1894 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1895 for (col
= 0; col
< srcWidth
; col
++) {
1896 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1897 CHAN_TO_UBYTE(src
[RCOMP
]),
1898 CHAN_TO_UBYTE(src
[GCOMP
]),
1899 CHAN_TO_UBYTE(src
[BCOMP
]) );
1904 for (col
= 0; col
< srcWidth
; col
++) {
1905 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1906 CHAN_TO_UBYTE(src
[RCOMP
]),
1907 CHAN_TO_UBYTE(src
[GCOMP
]),
1908 CHAN_TO_UBYTE(src
[BCOMP
]) );
1912 dstRow
+= dstRowStride
;
1915 free((void *) tempImage
);
1921 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1923 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1924 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1926 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1927 ASSERT(texelBytes
== 2);
1929 if (!ctx
->_ImageTransferState
&&
1930 !srcPacking
->SwapBytes
&&
1931 dstFormat
== MESA_FORMAT_RGBA5551
&&
1932 baseInternalFormat
== GL_RGBA
&&
1933 srcFormat
== GL_RGBA
&&
1934 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1935 /* simple memcpy path */
1936 memcpy_texture(ctx
, dims
,
1937 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1940 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1941 srcAddr
, srcPacking
);
1945 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1948 srcWidth
, srcHeight
, srcDepth
,
1949 srcFormat
, srcType
, srcAddr
,
1951 const GLchan
*src
=tempImage
;
1952 GLint img
, row
, col
;
1955 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1956 for (img
= 0; img
< srcDepth
; img
++) {
1957 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1958 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1959 + dstYoffset
* dstRowStride
1960 + dstXoffset
* texelBytes
;
1961 for (row
= 0; row
< srcHeight
; row
++) {
1962 GLushort
*dstUS
= (GLushort
*) dstRow
;
1963 for (col
= 0; col
< srcWidth
; col
++) {
1964 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1965 CHAN_TO_UBYTE(src
[GCOMP
]),
1966 CHAN_TO_UBYTE(src
[BCOMP
]),
1967 CHAN_TO_UBYTE(src
[ACOMP
]) );
1970 dstRow
+= dstRowStride
;
1973 free((void *) tempImage
);
1979 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1981 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1982 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1984 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1985 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1986 ASSERT(texelBytes
== 2);
1988 if (!ctx
->_ImageTransferState
&&
1989 !srcPacking
->SwapBytes
&&
1990 dstFormat
== MESA_FORMAT_ARGB1555
&&
1991 baseInternalFormat
== GL_RGBA
&&
1992 srcFormat
== GL_BGRA
&&
1993 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1994 /* simple memcpy path */
1995 memcpy_texture(ctx
, dims
,
1996 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1999 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2000 srcAddr
, srcPacking
);
2004 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2007 srcWidth
, srcHeight
, srcDepth
,
2008 srcFormat
, srcType
, srcAddr
,
2010 const GLchan
*src
=tempImage
;
2011 GLint img
, row
, col
;
2014 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2015 for (img
= 0; img
< srcDepth
; img
++) {
2016 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2017 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2018 + dstYoffset
* dstRowStride
2019 + dstXoffset
* texelBytes
;
2020 for (row
= 0; row
< srcHeight
; row
++) {
2021 GLushort
*dstUS
= (GLushort
*) dstRow
;
2022 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2023 for (col
= 0; col
< srcWidth
; col
++) {
2024 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
2025 CHAN_TO_UBYTE(src
[RCOMP
]),
2026 CHAN_TO_UBYTE(src
[GCOMP
]),
2027 CHAN_TO_UBYTE(src
[BCOMP
]) );
2032 for (col
= 0; col
< srcWidth
; col
++) {
2033 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2034 CHAN_TO_UBYTE(src
[RCOMP
]),
2035 CHAN_TO_UBYTE(src
[GCOMP
]),
2036 CHAN_TO_UBYTE(src
[BCOMP
]) );
2040 dstRow
+= dstRowStride
;
2043 free((void *) tempImage
);
2050 _mesa_texstore_al88(TEXSTORE_PARAMS
)
2052 const GLboolean littleEndian
= _mesa_little_endian();
2053 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2054 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2056 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2057 dstFormat
== MESA_FORMAT_AL88_REV
);
2058 ASSERT(texelBytes
== 2);
2060 if (!ctx
->_ImageTransferState
&&
2061 !srcPacking
->SwapBytes
&&
2062 dstFormat
== MESA_FORMAT_AL88
&&
2063 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2064 srcFormat
== GL_LUMINANCE_ALPHA
&&
2065 srcType
== GL_UNSIGNED_BYTE
&&
2067 /* simple memcpy path */
2068 memcpy_texture(ctx
, dims
,
2069 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2072 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2073 srcAddr
, srcPacking
);
2075 else if (!ctx
->_ImageTransferState
&&
2077 srcType
== GL_UNSIGNED_BYTE
&&
2078 can_swizzle(baseInternalFormat
) &&
2079 can_swizzle(srcFormat
)) {
2083 /* dstmap - how to swizzle from RGBA to dst format:
2085 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2086 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2094 dstmap
[2] = ZERO
; /* ? */
2095 dstmap
[3] = ONE
; /* ? */
2097 _mesa_swizzle_ubyte_image(ctx
, dims
,
2102 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2103 dstRowStride
, dstImageOffsets
,
2104 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2109 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2112 srcWidth
, srcHeight
, srcDepth
,
2113 srcFormat
, srcType
, srcAddr
,
2115 const GLchan
*src
= tempImage
;
2116 GLint img
, row
, col
;
2119 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2120 for (img
= 0; img
< srcDepth
; img
++) {
2121 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2122 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2123 + dstYoffset
* dstRowStride
2124 + dstXoffset
* texelBytes
;
2125 for (row
= 0; row
< srcHeight
; row
++) {
2126 GLushort
*dstUS
= (GLushort
*) dstRow
;
2127 if (dstFormat
== MESA_FORMAT_AL88
) {
2128 for (col
= 0; col
< srcWidth
; col
++) {
2129 /* src[0] is luminance, src[1] is alpha */
2130 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2131 CHAN_TO_UBYTE(src
[0]) );
2136 for (col
= 0; col
< srcWidth
; col
++) {
2137 /* src[0] is luminance, src[1] is alpha */
2138 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2139 CHAN_TO_UBYTE(src
[0]) );
2143 dstRow
+= dstRowStride
;
2146 free((void *) tempImage
);
2153 _mesa_texstore_al1616(TEXSTORE_PARAMS
)
2155 const GLboolean littleEndian
= _mesa_little_endian();
2156 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2157 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2159 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2160 dstFormat
== MESA_FORMAT_AL1616_REV
);
2161 ASSERT(texelBytes
== 4);
2163 if (!ctx
->_ImageTransferState
&&
2164 !srcPacking
->SwapBytes
&&
2165 dstFormat
== MESA_FORMAT_AL1616
&&
2166 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2167 srcFormat
== GL_LUMINANCE_ALPHA
&&
2168 srcType
== GL_UNSIGNED_SHORT
&&
2170 /* simple memcpy path */
2171 memcpy_texture(ctx
, dims
,
2172 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2175 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2176 srcAddr
, srcPacking
);
2180 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2183 srcWidth
, srcHeight
, srcDepth
,
2184 srcFormat
, srcType
, srcAddr
,
2186 const GLfloat
*src
= tempImage
;
2187 GLint img
, row
, col
;
2190 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2191 for (img
= 0; img
< srcDepth
; img
++) {
2192 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2193 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2194 + dstYoffset
* dstRowStride
2195 + dstXoffset
* texelBytes
;
2196 for (row
= 0; row
< srcHeight
; row
++) {
2197 GLuint
*dstUI
= (GLuint
*) dstRow
;
2198 if (dstFormat
== MESA_FORMAT_AL1616
) {
2199 for (col
= 0; col
< srcWidth
; col
++) {
2202 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2203 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2204 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2209 for (col
= 0; col
< srcWidth
; col
++) {
2212 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2213 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2214 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2218 dstRow
+= dstRowStride
;
2221 free((void *) tempImage
);
2228 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2230 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2231 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2233 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2234 ASSERT(texelBytes
== 1);
2236 if (!ctx
->_ImageTransferState
&&
2237 !srcPacking
->SwapBytes
&&
2238 baseInternalFormat
== GL_RGB
&&
2239 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2240 /* simple memcpy path */
2241 memcpy_texture(ctx
, dims
,
2242 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2245 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2246 srcAddr
, srcPacking
);
2250 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2253 srcWidth
, srcHeight
, srcDepth
,
2254 srcFormat
, srcType
, srcAddr
,
2256 const GLchan
*src
= tempImage
;
2257 GLint img
, row
, col
;
2260 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2261 for (img
= 0; img
< srcDepth
; img
++) {
2262 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2263 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2264 + dstYoffset
* dstRowStride
2265 + dstXoffset
* texelBytes
;
2266 for (row
= 0; row
< srcHeight
; row
++) {
2267 for (col
= 0; col
< srcWidth
; col
++) {
2268 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2269 CHAN_TO_UBYTE(src
[GCOMP
]),
2270 CHAN_TO_UBYTE(src
[BCOMP
]) );
2273 dstRow
+= dstRowStride
;
2276 free((void *) tempImage
);
2283 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2286 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2288 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2289 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2291 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2292 dstFormat
== MESA_FORMAT_L8
||
2293 dstFormat
== MESA_FORMAT_I8
);
2294 ASSERT(texelBytes
== 1);
2296 if (!ctx
->_ImageTransferState
&&
2297 !srcPacking
->SwapBytes
&&
2298 baseInternalFormat
== srcFormat
&&
2299 srcType
== GL_UNSIGNED_BYTE
) {
2300 /* simple memcpy path */
2301 memcpy_texture(ctx
, dims
,
2302 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2305 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2306 srcAddr
, srcPacking
);
2308 else if (!ctx
->_ImageTransferState
&&
2309 srcType
== GL_UNSIGNED_BYTE
&&
2310 can_swizzle(baseInternalFormat
) &&
2311 can_swizzle(srcFormat
)) {
2315 /* dstmap - how to swizzle from RGBA to dst format:
2317 if (dstFormat
== MESA_FORMAT_A8
) {
2323 dstmap
[1] = ZERO
; /* ? */
2324 dstmap
[2] = ZERO
; /* ? */
2325 dstmap
[3] = ONE
; /* ? */
2327 _mesa_swizzle_ubyte_image(ctx
, dims
,
2332 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2333 dstRowStride
, dstImageOffsets
,
2334 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2339 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2342 srcWidth
, srcHeight
, srcDepth
,
2343 srcFormat
, srcType
, srcAddr
,
2345 const GLchan
*src
= tempImage
;
2346 GLint img
, row
, col
;
2349 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2350 for (img
= 0; img
< srcDepth
; img
++) {
2351 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2352 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2353 + dstYoffset
* dstRowStride
2354 + dstXoffset
* texelBytes
;
2355 for (row
= 0; row
< srcHeight
; row
++) {
2356 for (col
= 0; col
< srcWidth
; col
++) {
2357 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2359 dstRow
+= dstRowStride
;
2363 free((void *) tempImage
);
2371 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2373 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2375 (void) dims
; (void) baseInternalFormat
;
2376 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2377 ASSERT(texelBytes
== 1);
2378 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2380 if (!ctx
->_ImageTransferState
&&
2381 !srcPacking
->SwapBytes
&&
2382 srcFormat
== GL_COLOR_INDEX
&&
2383 srcType
== GL_UNSIGNED_BYTE
) {
2384 /* simple memcpy path */
2385 memcpy_texture(ctx
, dims
,
2386 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2389 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2390 srcAddr
, srcPacking
);
2395 for (img
= 0; img
< srcDepth
; img
++) {
2396 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2397 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2398 + dstYoffset
* dstRowStride
2399 + dstXoffset
* texelBytes
;
2400 for (row
= 0; row
< srcHeight
; row
++) {
2401 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2402 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2403 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2404 srcType
, src
, srcPacking
,
2405 ctx
->_ImageTransferState
);
2406 dstRow
+= dstRowStride
;
2415 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2418 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2420 const GLboolean littleEndian
= _mesa_little_endian();
2421 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2423 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2425 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2426 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2427 ASSERT(texelBytes
== 2);
2428 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2429 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2430 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2431 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2432 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2434 /* always just memcpy since no pixel transfer ops apply */
2435 memcpy_texture(ctx
, dims
,
2436 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2439 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2440 srcAddr
, srcPacking
);
2442 /* Check if we need byte swapping */
2443 /* XXX the logic here _might_ be wrong */
2444 if (srcPacking
->SwapBytes
^
2445 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2446 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2449 for (img
= 0; img
< srcDepth
; img
++) {
2450 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2451 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2452 + dstYoffset
* dstRowStride
2453 + dstXoffset
* texelBytes
;
2454 for (row
= 0; row
< srcHeight
; row
++) {
2455 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2456 dstRow
+= dstRowStride
;
2464 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2466 const GLboolean littleEndian
= _mesa_little_endian();
2467 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2469 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2470 ASSERT(texelBytes
== 2);
2471 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2472 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2473 (srcFormat
== GL_DUDV_ATI
));
2474 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2476 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2478 /* simple memcpy path */
2479 memcpy_texture(ctx
, dims
,
2480 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2483 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2484 srcAddr
, srcPacking
);
2486 else if (srcType
== GL_BYTE
) {
2490 /* dstmap - how to swizzle from RGBA to dst format:
2500 dstmap
[2] = ZERO
; /* ? */
2501 dstmap
[3] = ONE
; /* ? */
2503 _mesa_swizzle_ubyte_image(ctx
, dims
,
2504 GL_LUMINANCE_ALPHA
, /* hack */
2505 GL_UNSIGNED_BYTE
, /* hack */
2506 GL_LUMINANCE_ALPHA
, /* hack */
2508 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2509 dstRowStride
, dstImageOffsets
,
2510 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2514 /* general path - note this is defined for 2d textures only */
2515 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2516 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2517 srcFormat
, srcType
);
2518 GLbyte
*tempImage
, *dst
, *src
;
2521 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2522 * components
* sizeof(GLbyte
));
2526 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2527 srcWidth
, srcHeight
,
2532 for (row
= 0; row
< srcHeight
; row
++) {
2533 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2534 dst
, srcFormat
, srcType
, src
,
2536 dst
+= srcWidth
* components
;
2541 dst
= (GLbyte
*) dstAddr
2542 + dstYoffset
* dstRowStride
2543 + dstXoffset
* texelBytes
;
2544 for (row
= 0; row
< srcHeight
; row
++) {
2545 memcpy(dst
, src
, srcWidth
* texelBytes
);
2546 dst
+= dstRowStride
;
2547 src
+= srcWidth
* texelBytes
;
2549 free((void *) tempImage
);
2556 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2559 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2561 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2562 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2564 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2565 ASSERT(texelBytes
== 1);
2567 /* XXX look at adding optimized paths */
2570 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2573 srcWidth
, srcHeight
, srcDepth
,
2574 srcFormat
, srcType
, srcAddr
,
2576 const GLfloat
*srcRow
= tempImage
;
2577 GLint img
, row
, col
;
2580 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2581 for (img
= 0; img
< srcDepth
; img
++) {
2582 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2583 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2584 + dstYoffset
* dstRowStride
2585 + dstXoffset
* texelBytes
;
2586 for (row
= 0; row
< srcHeight
; row
++) {
2587 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2588 for (col
= 0; col
< srcWidth
; col
++) {
2589 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2591 dstRow
+= dstRowStride
;
2594 free((void *) tempImage
);
2601 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2604 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2606 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2607 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2609 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2610 ASSERT(texelBytes
== 1);
2612 /* XXX look at adding optimized paths */
2615 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2618 srcWidth
, srcHeight
, srcDepth
,
2619 srcFormat
, srcType
, srcAddr
,
2621 const GLfloat
*srcRow
= tempImage
;
2622 GLint img
, row
, col
;
2625 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2626 for (img
= 0; img
< srcDepth
; img
++) {
2627 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2628 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2629 + dstYoffset
* dstRowStride
2630 + dstXoffset
* texelBytes
;
2631 for (row
= 0; row
< srcHeight
; row
++) {
2632 GLushort
*dstUS
= (GLushort
*) dstRow
;
2633 for (col
= 0; col
< srcWidth
; col
++) {
2634 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2635 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2637 dstRow
+= dstRowStride
;
2640 free((void *) tempImage
);
2647 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2650 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2652 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2653 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2655 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2656 ASSERT(texelBytes
== 4);
2660 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2663 srcWidth
, srcHeight
, srcDepth
,
2664 srcFormat
, srcType
, srcAddr
,
2666 const GLfloat
*srcRow
= tempImage
;
2667 GLint img
, row
, col
;
2670 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2671 for (img
= 0; img
< srcDepth
; img
++) {
2672 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2673 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2674 + dstYoffset
* dstRowStride
2675 + dstXoffset
* texelBytes
;
2676 for (row
= 0; row
< srcHeight
; row
++) {
2677 GLuint
*dstUI
= (GLuint
*) dstRow
;
2678 for (col
= 0; col
< srcWidth
; col
++) {
2679 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2680 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2681 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2685 dstRow
+= dstRowStride
;
2688 free((void *) tempImage
);
2696 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV
2699 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2701 const GLboolean littleEndian
= _mesa_little_endian();
2702 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2703 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2705 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2706 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2707 ASSERT(texelBytes
== 4);
2709 if (!ctx
->_ImageTransferState
&&
2710 !srcPacking
->SwapBytes
&&
2711 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2712 baseInternalFormat
== GL_RGBA
&&
2713 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2714 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2715 /* simple memcpy path */
2716 memcpy_texture(ctx
, dims
,
2717 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2720 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2721 srcAddr
, srcPacking
);
2723 else if (!ctx
->_ImageTransferState
&&
2724 !srcPacking
->SwapBytes
&&
2725 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2726 baseInternalFormat
== GL_RGBA
&&
2727 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2728 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2729 /* simple memcpy path */
2730 memcpy_texture(ctx
, dims
,
2731 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2734 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2735 srcAddr
, srcPacking
);
2737 else if (!ctx
->_ImageTransferState
&&
2738 (srcType
== GL_BYTE
) &&
2739 can_swizzle(baseInternalFormat
) &&
2740 can_swizzle(srcFormat
)) {
2744 /* dstmap - how to swizzle from RGBA to dst format:
2746 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2747 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2760 _mesa_swizzle_ubyte_image(ctx
, dims
,
2765 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2766 dstRowStride
, dstImageOffsets
,
2767 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2772 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2775 srcWidth
, srcHeight
, srcDepth
,
2776 srcFormat
, srcType
, srcAddr
,
2778 const GLfloat
*srcRow
= tempImage
;
2779 GLint img
, row
, col
;
2782 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2783 for (img
= 0; img
< srcDepth
; img
++) {
2784 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2785 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2786 + dstYoffset
* dstRowStride
2787 + dstXoffset
* texelBytes
;
2788 for (row
= 0; row
< srcHeight
; row
++) {
2789 GLuint
*dstUI
= (GLuint
*) dstRow
;
2790 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2791 for (col
= 0; col
< srcWidth
; col
++) {
2792 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2793 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2794 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2795 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2800 for (col
= 0; col
< srcWidth
; col
++) {
2801 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2802 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2803 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2804 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2808 dstRow
+= dstRowStride
;
2811 free((void *) tempImage
);
2818 * Store a combined depth/stencil texture image.
2821 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2823 const GLuint depthScale
= 0xffffff;
2824 const GLint srcRowStride
2825 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2829 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2830 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2831 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2833 /* In case we only upload depth we need to preserve the stencil */
2834 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2835 for (img
= 0; img
< srcDepth
; img
++) {
2836 GLuint
*dstRow
= (GLuint
*) dstAddr
2837 + dstImageOffsets
[dstZoffset
+ img
]
2838 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2841 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2842 srcWidth
, srcHeight
,
2845 for (row
= 0; row
< srcHeight
; row
++) {
2846 GLuint depth
[MAX_WIDTH
];
2848 _mesa_unpack_depth_span(ctx
, srcWidth
,
2849 GL_UNSIGNED_INT
, /* dst type */
2850 depth
, /* dst addr */
2852 srcType
, src
, srcPacking
);
2854 for (i
= 0; i
< srcWidth
; i
++)
2855 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2857 src
+= srcRowStride
;
2858 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2862 else if (ctx
->Pixel
.DepthScale
== 1.0f
&&
2863 ctx
->Pixel
.DepthBias
== 0.0f
&&
2864 !srcPacking
->SwapBytes
) {
2866 memcpy_texture(ctx
, dims
,
2867 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2870 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2871 srcAddr
, srcPacking
);
2875 const GLint srcRowStride
2876 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2880 for (img
= 0; img
< srcDepth
; img
++) {
2881 GLuint
*dstRow
= (GLuint
*) dstAddr
2882 + dstImageOffsets
[dstZoffset
+ img
]
2883 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2886 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2887 srcWidth
, srcHeight
,
2890 for (row
= 0; row
< srcHeight
; row
++) {
2891 GLubyte stencil
[MAX_WIDTH
];
2893 /* the 24 depth bits will be in the high position: */
2894 _mesa_unpack_depth_span(ctx
, srcWidth
,
2895 GL_UNSIGNED_INT_24_8_EXT
, /* dst type */
2896 dstRow
, /* dst addr */
2898 srcType
, src
, srcPacking
);
2899 /* get the 8-bit stencil values */
2900 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2901 GL_UNSIGNED_BYTE
, /* dst type */
2902 stencil
, /* dst addr */
2903 srcType
, src
, srcPacking
,
2904 ctx
->_ImageTransferState
);
2905 /* merge stencil values into depth values */
2906 for (i
= 0; i
< srcWidth
; i
++)
2907 dstRow
[i
] |= stencil
[i
];
2909 src
+= srcRowStride
;
2910 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2919 * Store a combined depth/stencil texture image.
2922 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2924 const GLuint depthScale
= 0xffffff;
2925 const GLint srcRowStride
2926 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2930 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2931 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2932 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2934 /* In case we only upload depth we need to preserve the stencil */
2935 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2936 for (img
= 0; img
< srcDepth
; img
++) {
2937 GLuint
*dstRow
= (GLuint
*) dstAddr
2938 + dstImageOffsets
[dstZoffset
+ img
]
2939 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2942 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2943 srcWidth
, srcHeight
,
2946 for (row
= 0; row
< srcHeight
; row
++) {
2947 GLuint depth
[MAX_WIDTH
];
2949 _mesa_unpack_depth_span(ctx
, srcWidth
,
2950 GL_UNSIGNED_INT
, /* dst type */
2951 depth
, /* dst addr */
2953 srcType
, src
, srcPacking
);
2955 for (i
= 0; i
< srcWidth
; i
++)
2956 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2958 src
+= srcRowStride
;
2959 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2964 for (img
= 0; img
< srcDepth
; img
++) {
2965 GLuint
*dstRow
= (GLuint
*) dstAddr
2966 + dstImageOffsets
[dstZoffset
+ img
]
2967 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2970 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2971 srcWidth
, srcHeight
,
2974 for (row
= 0; row
< srcHeight
; row
++) {
2975 GLubyte stencil
[MAX_WIDTH
];
2977 /* the 24 depth bits will be in the low position: */
2978 _mesa_unpack_depth_span(ctx
, srcWidth
,
2979 GL_UNSIGNED_INT
, /* dst type */
2980 dstRow
, /* dst addr */
2982 srcType
, src
, srcPacking
);
2983 /* get the 8-bit stencil values */
2984 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2985 GL_UNSIGNED_BYTE
, /* dst type */
2986 stencil
, /* dst addr */
2987 srcType
, src
, srcPacking
,
2988 ctx
->_ImageTransferState
);
2989 /* merge stencil values into depth values */
2990 for (i
= 0; i
< srcWidth
; i
++)
2991 dstRow
[i
] |= stencil
[i
] << 24;
2993 src
+= srcRowStride
;
2994 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3002 * Store an image in any of the formats:
3003 * _mesa_texformat_rgba_float32
3004 * _mesa_texformat_rgb_float32
3005 * _mesa_texformat_alpha_float32
3006 * _mesa_texformat_luminance_float32
3007 * _mesa_texformat_luminance_alpha_float32
3008 * _mesa_texformat_intensity_float32
3011 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3013 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3014 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3015 const GLint components
= _mesa_components_in_format(baseFormat
);
3017 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3018 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3019 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3020 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3021 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3022 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3023 ASSERT(baseInternalFormat
== GL_RGBA
||
3024 baseInternalFormat
== GL_RGB
||
3025 baseInternalFormat
== GL_ALPHA
||
3026 baseInternalFormat
== GL_LUMINANCE
||
3027 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3028 baseInternalFormat
== GL_INTENSITY
);
3029 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3031 if (!ctx
->_ImageTransferState
&&
3032 !srcPacking
->SwapBytes
&&
3033 baseInternalFormat
== srcFormat
&&
3034 srcType
== GL_FLOAT
) {
3035 /* simple memcpy path */
3036 memcpy_texture(ctx
, dims
,
3037 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3040 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3041 srcAddr
, srcPacking
);
3045 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3048 srcWidth
, srcHeight
, srcDepth
,
3049 srcFormat
, srcType
, srcAddr
,
3051 const GLfloat
*srcRow
= tempImage
;
3056 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
3057 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3058 for (img
= 0; img
< srcDepth
; img
++) {
3059 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3060 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3061 + dstYoffset
* dstRowStride
3062 + dstXoffset
* texelBytes
;
3063 for (row
= 0; row
< srcHeight
; row
++) {
3064 memcpy(dstRow
, srcRow
, bytesPerRow
);
3065 dstRow
+= dstRowStride
;
3066 srcRow
+= srcWidth
* components
;
3070 free((void *) tempImage
);
3077 * As above, but store 16-bit floats.
3080 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3082 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3083 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3084 const GLint components
= _mesa_components_in_format(baseFormat
);
3086 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3087 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3088 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3089 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3090 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3091 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3092 ASSERT(baseInternalFormat
== GL_RGBA
||
3093 baseInternalFormat
== GL_RGB
||
3094 baseInternalFormat
== GL_ALPHA
||
3095 baseInternalFormat
== GL_LUMINANCE
||
3096 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3097 baseInternalFormat
== GL_INTENSITY
);
3098 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3100 if (!ctx
->_ImageTransferState
&&
3101 !srcPacking
->SwapBytes
&&
3102 baseInternalFormat
== srcFormat
&&
3103 srcType
== GL_HALF_FLOAT_ARB
) {
3104 /* simple memcpy path */
3105 memcpy_texture(ctx
, dims
,
3106 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3109 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3110 srcAddr
, srcPacking
);
3114 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3117 srcWidth
, srcHeight
, srcDepth
,
3118 srcFormat
, srcType
, srcAddr
,
3120 const GLfloat
*src
= tempImage
;
3124 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
3125 for (img
= 0; img
< srcDepth
; img
++) {
3126 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3127 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3128 + dstYoffset
* dstRowStride
3129 + dstXoffset
* texelBytes
;
3130 for (row
= 0; row
< srcHeight
; row
++) {
3131 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3133 for (i
= 0; i
< srcWidth
* components
; i
++) {
3134 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3136 dstRow
+= dstRowStride
;
3137 src
+= srcWidth
* components
;
3141 free((void *) tempImage
);
3147 #if FEATURE_EXT_texture_sRGB
3149 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3151 gl_format newDstFormat
;
3154 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3156 /* reuse normal rgb texstore code */
3157 newDstFormat
= MESA_FORMAT_RGB888
;
3159 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3160 newDstFormat
, dstAddr
,
3161 dstXoffset
, dstYoffset
, dstZoffset
,
3162 dstRowStride
, dstImageOffsets
,
3163 srcWidth
, srcHeight
, srcDepth
,
3165 srcAddr
, srcPacking
);
3171 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3173 gl_format newDstFormat
;
3176 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3178 /* reuse normal rgba texstore code */
3179 newDstFormat
= MESA_FORMAT_RGBA8888
;
3180 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3181 newDstFormat
, dstAddr
,
3182 dstXoffset
, dstYoffset
, dstZoffset
,
3183 dstRowStride
, dstImageOffsets
,
3184 srcWidth
, srcHeight
, srcDepth
,
3186 srcAddr
, srcPacking
);
3192 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3194 gl_format newDstFormat
;
3197 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3199 /* reuse normal rgba texstore code */
3200 newDstFormat
= MESA_FORMAT_ARGB8888
;
3202 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3203 newDstFormat
, dstAddr
,
3204 dstXoffset
, dstYoffset
, dstZoffset
,
3205 dstRowStride
, dstImageOffsets
,
3206 srcWidth
, srcHeight
, srcDepth
,
3208 srcAddr
, srcPacking
);
3214 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3216 gl_format newDstFormat
;
3219 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3221 newDstFormat
= MESA_FORMAT_L8
;
3223 /* _mesa_textore_a8 handles luminance8 too */
3224 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3225 newDstFormat
, dstAddr
,
3226 dstXoffset
, dstYoffset
, dstZoffset
,
3227 dstRowStride
, dstImageOffsets
,
3228 srcWidth
, srcHeight
, srcDepth
,
3230 srcAddr
, srcPacking
);
3236 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3238 gl_format newDstFormat
;
3241 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3243 /* reuse normal luminance/alpha texstore code */
3244 newDstFormat
= MESA_FORMAT_AL88
;
3246 k
= _mesa_texstore_al88(ctx
, dims
, baseInternalFormat
,
3247 newDstFormat
, dstAddr
,
3248 dstXoffset
, dstYoffset
, dstZoffset
,
3249 dstRowStride
, dstImageOffsets
,
3250 srcWidth
, srcHeight
, srcDepth
,
3252 srcAddr
, srcPacking
);
3258 /* these are used only in texstore_funcs[] below */
3259 #define _mesa_texstore_srgb8 NULL
3260 #define _mesa_texstore_srgba8 NULL
3261 #define _mesa_texstore_sargb8 NULL
3262 #define _mesa_texstore_sl8 NULL
3263 #define _mesa_texstore_sla8 NULL
3265 #endif /* FEATURE_EXT_texture_sRGB */
3271 * Table mapping MESA_FORMAT_8 to _mesa_texstore_*()
3272 * XXX this is somewhat temporary.
3274 static const struct {
3276 StoreTexImageFunc Store
;
3278 texstore_funcs
[MESA_FORMAT_COUNT
] =
3280 { MESA_FORMAT_NONE
, NULL
},
3281 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
3282 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
3283 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
3284 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
3285 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
3286 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
3287 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
3288 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
3289 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
3290 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
3291 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
3292 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
3293 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
3294 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
3295 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
3296 { MESA_FORMAT_AL88
, _mesa_texstore_al88
},
3297 { MESA_FORMAT_AL88_REV
, _mesa_texstore_al88
},
3298 { MESA_FORMAT_AL1616
, _mesa_texstore_al1616
},
3299 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_al1616
},
3300 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
3301 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
3302 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
3303 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
3304 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
3305 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
3306 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
3307 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
3308 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
3309 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3310 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
3311 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
3312 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3313 { MESA_FORMAT_S8
, NULL
/*_mesa_texstore_s8*/ },
3314 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3315 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3316 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3317 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3318 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3319 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3320 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3321 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3322 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3323 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3324 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3325 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3326 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3327 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3328 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3329 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3330 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3331 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3332 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3333 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3334 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3335 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3336 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3337 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3338 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3339 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3340 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3341 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3343 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
3344 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
3345 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
3347 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3348 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3350 { MESA_FORMAT_SIGNED_R_16
, NULL
/*_mesa_texstore_signed_r16*/ },
3351 { MESA_FORMAT_SIGNED_RG_16
, NULL
/*_mesa_texstore_signed_rg16*/ },
3352 { MESA_FORMAT_SIGNED_RGB_16
, NULL
/*_mesa_texstore_signed_rgb16*/ },
3353 { MESA_FORMAT_SIGNED_RGBA_16
, NULL
/*_mesa_texstore_signed_rgba16*/ },
3358 _mesa_texstore_null(TEXSTORE_PARAMS
)
3360 (void) ctx
; (void) dims
;
3361 (void) baseInternalFormat
;
3364 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
3365 (void) dstRowStride
; (void) dstImageOffsets
;
3366 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3367 (void) srcFormat
; (void) srcType
;
3371 /* should never happen */
3372 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3378 * Return the StoreTexImageFunc pointer to store an image in the given format.
3380 static StoreTexImageFunc
3381 _mesa_get_texstore_func(gl_format format
)
3385 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
3386 ASSERT(texstore_funcs
[i
].Name
== i
);
3389 ASSERT(texstore_funcs
[format
].Name
== format
);
3391 if (texstore_funcs
[format
].Store
)
3392 return texstore_funcs
[format
].Store
;
3394 return _mesa_texstore_null
;
3399 * Store user data into texture memory.
3400 * Called via glTex[Sub]Image1/2/3D()
3403 _mesa_texstore(TEXSTORE_PARAMS
)
3405 StoreTexImageFunc storeImage
;
3408 storeImage
= _mesa_get_texstore_func(dstFormat
);
3410 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3411 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3412 dstRowStride
, dstImageOffsets
,
3413 srcWidth
, srcHeight
, srcDepth
,
3414 srcFormat
, srcType
, srcAddr
, srcPacking
);
3420 * Check if an unpack PBO is active prior to fetching a texture image.
3421 * If so, do bounds checking and map the buffer into main memory.
3422 * Any errors detected will be recorded.
3423 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3426 _mesa_validate_pbo_teximage(GLcontext
*ctx
, GLuint dimensions
,
3427 GLsizei width
, GLsizei height
, GLsizei depth
,
3428 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3429 const struct gl_pixelstore_attrib
*unpack
,
3430 const char *funcName
)
3434 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
3438 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
3439 format
, type
, pixels
)) {
3440 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3444 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3445 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
3447 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3451 return ADD_POINTERS(buf
, pixels
);
3456 * Check if an unpack PBO is active prior to fetching a compressed texture
3458 * If so, do bounds checking and map the buffer into main memory.
3459 * Any errors detected will be recorded.
3460 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3463 _mesa_validate_pbo_compressed_teximage(GLcontext
*ctx
,
3464 GLsizei imageSize
, const GLvoid
*pixels
,
3465 const struct gl_pixelstore_attrib
*packing
,
3466 const char *funcName
)
3470 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
3471 /* not using a PBO - return pointer unchanged */
3474 if ((const GLubyte
*) pixels
+ imageSize
>
3475 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
3476 /* out of bounds read! */
3477 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3481 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3482 GL_READ_ONLY_ARB
, packing
->BufferObj
);
3484 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3488 return ADD_POINTERS(buf
, pixels
);
3493 * This function must be called after either of the validate_pbo_*_teximage()
3494 * functions. It unmaps the PBO buffer if it was mapped earlier.
3497 _mesa_unmap_teximage_pbo(GLcontext
*ctx
,
3498 const struct gl_pixelstore_attrib
*unpack
)
3500 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
3501 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3507 /** Return texture size in bytes */
3509 texture_size(const struct gl_texture_image
*texImage
)
3511 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
3512 texImage
->Height
, texImage
->Depth
);
3517 /** Return row stride in bytes */
3519 texture_row_stride(const struct gl_texture_image
*texImage
)
3521 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
3529 * This is the software fallback for Driver.TexImage1D()
3530 * and Driver.CopyTexImage1D().
3531 * \sa _mesa_store_teximage2d()
3532 * Note that the width may not be the actual texture width since it may
3533 * be changed by convolution w/ GL_REDUCE. The texImage->Width field will
3534 * have the actual texture size.
3537 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3538 GLint internalFormat
,
3539 GLint width
, GLint border
,
3540 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3541 const struct gl_pixelstore_attrib
*packing
,
3542 struct gl_texture_object
*texObj
,
3543 struct gl_texture_image
*texImage
)
3548 /* allocate memory */
3549 sizeInBytes
= texture_size(texImage
);
3550 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3551 if (!texImage
->Data
) {
3552 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3556 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3557 pixels
, packing
, "glTexImage1D");
3559 /* Note: we check for a NULL image pointer here, _after_ we allocated
3560 * memory for the texture. That's what the GL spec calls for.
3565 const GLint dstRowStride
= 0;
3566 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3567 texImage
->TexFormat
,
3569 0, 0, 0, /* dstX/Y/Zoffset */
3571 texImage
->ImageOffsets
,
3573 format
, type
, pixels
, packing
);
3575 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3579 _mesa_unmap_teximage_pbo(ctx
, packing
);
3584 * This is the software fallback for Driver.TexImage2D()
3585 * and Driver.CopyTexImage2D().
3587 * This function is oriented toward storing images in main memory, rather
3588 * than VRAM. Device driver's can easily plug in their own replacement.
3590 * Note: width and height may be pre-convolved dimensions, but
3591 * texImage->Width and texImage->Height will be post-convolved dimensions.
3594 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3595 GLint internalFormat
,
3596 GLint width
, GLint height
, GLint border
,
3597 GLenum format
, GLenum type
, const void *pixels
,
3598 const struct gl_pixelstore_attrib
*packing
,
3599 struct gl_texture_object
*texObj
,
3600 struct gl_texture_image
*texImage
)
3605 /* allocate memory */
3606 sizeInBytes
= texture_size(texImage
);
3607 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3608 if (!texImage
->Data
) {
3609 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3613 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3614 pixels
, packing
, "glTexImage2D");
3616 /* Note: we check for a NULL image pointer here, _after_ we allocated
3617 * memory for the texture. That's what the GL spec calls for.
3622 GLint dstRowStride
= texture_row_stride(texImage
);
3623 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3624 texImage
->TexFormat
,
3626 0, 0, 0, /* dstX/Y/Zoffset */
3628 texImage
->ImageOffsets
,
3630 format
, type
, pixels
, packing
);
3632 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3636 _mesa_unmap_teximage_pbo(ctx
, packing
);
3642 * This is the software fallback for Driver.TexImage3D()
3643 * and Driver.CopyTexImage3D().
3644 * \sa _mesa_store_teximage2d()
3647 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3648 GLint internalFormat
,
3649 GLint width
, GLint height
, GLint depth
, GLint border
,
3650 GLenum format
, GLenum type
, const void *pixels
,
3651 const struct gl_pixelstore_attrib
*packing
,
3652 struct gl_texture_object
*texObj
,
3653 struct gl_texture_image
*texImage
)
3658 /* allocate memory */
3659 sizeInBytes
= texture_size(texImage
);
3660 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3661 if (!texImage
->Data
) {
3662 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3666 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3667 type
, pixels
, packing
, "glTexImage3D");
3669 /* Note: we check for a NULL image pointer here, _after_ we allocated
3670 * memory for the texture. That's what the GL spec calls for.
3675 GLint dstRowStride
= texture_row_stride(texImage
);
3676 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3677 texImage
->TexFormat
,
3679 0, 0, 0, /* dstX/Y/Zoffset */
3681 texImage
->ImageOffsets
,
3682 width
, height
, depth
,
3683 format
, type
, pixels
, packing
);
3685 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3689 _mesa_unmap_teximage_pbo(ctx
, packing
);
3696 * This is the software fallback for Driver.TexSubImage1D()
3697 * and Driver.CopyTexSubImage1D().
3700 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3701 GLint xoffset
, GLint width
,
3702 GLenum format
, GLenum type
, const void *pixels
,
3703 const struct gl_pixelstore_attrib
*packing
,
3704 struct gl_texture_object
*texObj
,
3705 struct gl_texture_image
*texImage
)
3707 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3708 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3709 pixels
, packing
, "glTexSubImage1D");
3714 const GLint dstRowStride
= 0;
3715 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3716 texImage
->TexFormat
,
3718 xoffset
, 0, 0, /* offsets */
3720 texImage
->ImageOffsets
,
3722 format
, type
, pixels
, packing
);
3724 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
3728 _mesa_unmap_teximage_pbo(ctx
, packing
);
3734 * This is the software fallback for Driver.TexSubImage2D()
3735 * and Driver.CopyTexSubImage2D().
3738 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3739 GLint xoffset
, GLint yoffset
,
3740 GLint width
, GLint height
,
3741 GLenum format
, GLenum type
, const void *pixels
,
3742 const struct gl_pixelstore_attrib
*packing
,
3743 struct gl_texture_object
*texObj
,
3744 struct gl_texture_image
*texImage
)
3746 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3747 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3748 pixels
, packing
, "glTexSubImage2D");
3753 GLint dstRowStride
= texture_row_stride(texImage
);
3754 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3755 texImage
->TexFormat
,
3757 xoffset
, yoffset
, 0,
3759 texImage
->ImageOffsets
,
3761 format
, type
, pixels
, packing
);
3763 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
3767 _mesa_unmap_teximage_pbo(ctx
, packing
);
3772 * This is the software fallback for Driver.TexSubImage3D().
3773 * and Driver.CopyTexSubImage3D().
3776 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3777 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3778 GLint width
, GLint height
, GLint depth
,
3779 GLenum format
, GLenum type
, const void *pixels
,
3780 const struct gl_pixelstore_attrib
*packing
,
3781 struct gl_texture_object
*texObj
,
3782 struct gl_texture_image
*texImage
)
3784 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3785 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3786 type
, pixels
, packing
,
3792 GLint dstRowStride
= texture_row_stride(texImage
);
3793 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3794 texImage
->TexFormat
,
3796 xoffset
, yoffset
, zoffset
,
3798 texImage
->ImageOffsets
,
3799 width
, height
, depth
,
3800 format
, type
, pixels
, packing
);
3802 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
3806 _mesa_unmap_teximage_pbo(ctx
, packing
);
3811 * Fallback for Driver.CompressedTexImage1D()
3814 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3815 GLint internalFormat
,
3816 GLint width
, GLint border
,
3817 GLsizei imageSize
, const GLvoid
*data
,
3818 struct gl_texture_object
*texObj
,
3819 struct gl_texture_image
*texImage
)
3821 /* this space intentionally left blank */
3823 (void) target
; (void) level
;
3824 (void) internalFormat
;
3825 (void) width
; (void) border
;
3826 (void) imageSize
; (void) data
;
3834 * Fallback for Driver.CompressedTexImage2D()
3837 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3838 GLint internalFormat
,
3839 GLint width
, GLint height
, GLint border
,
3840 GLsizei imageSize
, const GLvoid
*data
,
3841 struct gl_texture_object
*texObj
,
3842 struct gl_texture_image
*texImage
)
3844 (void) width
; (void) height
; (void) border
;
3846 /* This is pretty simple, basically just do a memcpy without worrying
3847 * about the usual image unpacking or image transfer operations.
3851 ASSERT(texImage
->Width
> 0);
3852 ASSERT(texImage
->Height
> 0);
3853 ASSERT(texImage
->Depth
== 1);
3854 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
3856 /* allocate storage */
3857 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
3858 if (!texImage
->Data
) {
3859 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
3863 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3865 "glCompressedTexImage2D");
3870 memcpy(texImage
->Data
, data
, imageSize
);
3872 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3878 * Fallback for Driver.CompressedTexImage3D()
3881 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3882 GLint internalFormat
,
3883 GLint width
, GLint height
, GLint depth
,
3885 GLsizei imageSize
, const GLvoid
*data
,
3886 struct gl_texture_object
*texObj
,
3887 struct gl_texture_image
*texImage
)
3889 /* this space intentionally left blank */
3891 (void) target
; (void) level
;
3892 (void) internalFormat
;
3893 (void) width
; (void) height
; (void) depth
;
3895 (void) imageSize
; (void) data
;
3903 * Fallback for Driver.CompressedTexSubImage1D()
3906 _mesa_store_compressed_texsubimage1d(GLcontext
*ctx
, GLenum target
,
3908 GLint xoffset
, GLsizei width
,
3910 GLsizei imageSize
, const GLvoid
*data
,
3911 struct gl_texture_object
*texObj
,
3912 struct gl_texture_image
*texImage
)
3914 /* there are no compressed 1D texture formats yet */
3916 (void) target
; (void) level
;
3917 (void) xoffset
; (void) width
;
3919 (void) imageSize
; (void) data
;
3926 * Fallback for Driver.CompressedTexSubImage2D()
3929 _mesa_store_compressed_texsubimage2d(GLcontext
*ctx
, GLenum target
,
3931 GLint xoffset
, GLint yoffset
,
3932 GLsizei width
, GLsizei height
,
3934 GLsizei imageSize
, const GLvoid
*data
,
3935 struct gl_texture_object
*texObj
,
3936 struct gl_texture_image
*texImage
)
3938 GLint bytesPerRow
, destRowStride
, srcRowStride
;
3942 const gl_format texFormat
= texImage
->TexFormat
;
3943 const GLint destWidth
= texImage
->Width
;
3946 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3951 /* these should have been caught sooner */
3952 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
3953 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
3954 ASSERT((xoffset
% bw
) == 0);
3955 ASSERT((yoffset
% bh
) == 0);
3957 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3958 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3960 "glCompressedTexSubImage2D");
3964 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
3965 src
= (const GLubyte
*) data
;
3967 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
3968 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
3969 texFormat
, destWidth
,
3970 (GLubyte
*) texImage
->Data
);
3972 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
3973 rows
= height
/ bh
; /* rows in blocks */
3975 /* copy rows of blocks */
3976 for (i
= 0; i
< rows
; i
++) {
3977 memcpy(dest
, src
, bytesPerRow
);
3978 dest
+= destRowStride
;
3979 src
+= srcRowStride
;
3982 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3987 * Fallback for Driver.CompressedTexSubImage3D()
3990 _mesa_store_compressed_texsubimage3d(GLcontext
*ctx
, GLenum target
,
3992 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3993 GLsizei width
, GLsizei height
, GLsizei depth
,
3995 GLsizei imageSize
, const GLvoid
*data
,
3996 struct gl_texture_object
*texObj
,
3997 struct gl_texture_image
*texImage
)
3999 /* there are no compressed 3D texture formats yet */
4001 (void) target
; (void) level
;
4002 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4003 (void) width
; (void) height
; (void) depth
;
4005 (void) imageSize
; (void) data
;