2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_s3tc.h"
81 * Texture image storage function.
83 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
87 * Return GL_TRUE if the given image format is one that be converted
88 * to another format by swizzling.
91 can_swizzle(GLenum logicalBaseFormat
)
93 switch (logicalBaseFormat
) {
96 case GL_LUMINANCE_ALPHA
:
132 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
133 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
134 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
135 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
138 static const struct {
141 GLubyte from_rgba
[6];
142 } mappings
[MAX_IDX
] =
152 MAP4(ZERO
, ZERO
, ZERO
, 0),
182 MAP4(0, ZERO
, ZERO
, ONE
),
188 MAP4(ZERO
, 0, ZERO
, ONE
),
194 MAP4(ZERO
, ZERO
, 0, ONE
),
218 MAP4(0, 1, ZERO
, ONE
),
226 * Convert a GL image format enum to an IDX_* value (see above).
229 get_map_idx(GLenum value
)
232 case GL_LUMINANCE
: return IDX_LUMINANCE
;
233 case GL_ALPHA
: return IDX_ALPHA
;
234 case GL_INTENSITY
: return IDX_INTENSITY
;
235 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
236 case GL_RGB
: return IDX_RGB
;
237 case GL_RGBA
: return IDX_RGBA
;
238 case GL_RED
: return IDX_RED
;
239 case GL_GREEN
: return IDX_GREEN
;
240 case GL_BLUE
: return IDX_BLUE
;
241 case GL_BGR
: return IDX_BGR
;
242 case GL_BGRA
: return IDX_BGRA
;
243 case GL_ABGR_EXT
: return IDX_ABGR
;
244 case GL_RG
: return IDX_RG
;
246 _mesa_problem(NULL
, "Unexpected inFormat");
253 * When promoting texture formats (see below) we need to compute the
254 * mapping of dest components back to source components.
255 * This function does that.
256 * \param inFormat the incoming format of the texture
257 * \param outFormat the final texture format
258 * \return map[6] a full 6-component map
261 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
264 const int inFmt
= get_map_idx(inFormat
);
265 const int outFmt
= get_map_idx(outFormat
);
266 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
267 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
270 for (i
= 0; i
< 4; i
++)
271 map
[i
] = in2rgba
[rgba2out
[i
]];
277 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
278 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
279 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
291 * Make a temporary (color) texture image with GLfloat components.
292 * Apply all needed pixel unpacking and pixel transfer operations.
293 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
294 * Suppose the user specifies GL_LUMINANCE as the internal texture format
295 * but the graphics hardware doesn't support luminance textures. So, we might
296 * use an RGB hardware format instead.
297 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
299 * \param ctx the rendering context
300 * \param dims image dimensions: 1, 2 or 3
301 * \param logicalBaseFormat basic texture derived from the user's
302 * internal texture format value
303 * \param textureBaseFormat the actual basic format of the texture
304 * \param srcWidth source image width
305 * \param srcHeight source image height
306 * \param srcDepth source image depth
307 * \param srcFormat source image format
308 * \param srcType source image type
309 * \param srcAddr source image address
310 * \param srcPacking source image pixel packing
311 * \return resulting image with format = textureBaseFormat and type = GLfloat.
314 make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
315 GLenum logicalBaseFormat
,
316 GLenum textureBaseFormat
,
317 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
318 GLenum srcFormat
, GLenum srcType
,
319 const GLvoid
*srcAddr
,
320 const struct gl_pixelstore_attrib
*srcPacking
,
321 GLbitfield transferOps
)
324 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
325 const GLint srcStride
=
326 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
330 ASSERT(dims
>= 1 && dims
<= 3);
332 ASSERT(logicalBaseFormat
== GL_RGBA
||
333 logicalBaseFormat
== GL_RGB
||
334 logicalBaseFormat
== GL_RG
||
335 logicalBaseFormat
== GL_RED
||
336 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
337 logicalBaseFormat
== GL_LUMINANCE
||
338 logicalBaseFormat
== GL_ALPHA
||
339 logicalBaseFormat
== GL_INTENSITY
||
340 logicalBaseFormat
== GL_COLOR_INDEX
||
341 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
343 ASSERT(textureBaseFormat
== GL_RGBA
||
344 textureBaseFormat
== GL_RGB
||
345 textureBaseFormat
== GL_RG
||
346 textureBaseFormat
== GL_RED
||
347 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
348 textureBaseFormat
== GL_LUMINANCE
||
349 textureBaseFormat
== GL_ALPHA
||
350 textureBaseFormat
== GL_INTENSITY
||
351 textureBaseFormat
== GL_COLOR_INDEX
||
352 textureBaseFormat
== GL_DEPTH_COMPONENT
);
354 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
355 * components
* sizeof(GLfloat
));
360 for (img
= 0; img
< srcDepth
; img
++) {
362 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
366 for (row
= 0; row
< srcHeight
; row
++) {
367 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
368 dst
, srcFormat
, srcType
, src
,
369 srcPacking
, transferOps
);
370 dst
+= srcWidth
* components
;
375 if (logicalBaseFormat
!= textureBaseFormat
) {
377 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
378 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
383 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
384 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
385 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
387 /* The actual texture format should have at least as many components
388 * as the logical texture format.
390 ASSERT(texComponents
>= logComponents
);
392 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
393 * texComponents
* sizeof(GLfloat
));
399 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
401 n
= srcWidth
* srcHeight
* srcDepth
;
402 for (i
= 0; i
< n
; i
++) {
404 for (k
= 0; k
< texComponents
; k
++) {
407 newImage
[i
* texComponents
+ k
] = 0.0F
;
409 newImage
[i
* texComponents
+ k
] = 1.0F
;
411 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
416 tempImage
= newImage
;
424 * Make temporary image with uint pixel values. Used for unsigned
425 * integer-valued textures.
428 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
429 GLenum logicalBaseFormat
,
430 GLenum textureBaseFormat
,
431 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
432 GLenum srcFormat
, GLenum srcType
,
433 const GLvoid
*srcAddr
,
434 const struct gl_pixelstore_attrib
*srcPacking
)
437 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
438 const GLint srcStride
=
439 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
443 ASSERT(dims
>= 1 && dims
<= 3);
445 ASSERT(logicalBaseFormat
== GL_RGBA
||
446 logicalBaseFormat
== GL_RGB
||
447 logicalBaseFormat
== GL_RG
||
448 logicalBaseFormat
== GL_RED
||
449 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
450 logicalBaseFormat
== GL_LUMINANCE
||
451 logicalBaseFormat
== GL_INTENSITY
||
452 logicalBaseFormat
== GL_ALPHA
);
454 ASSERT(textureBaseFormat
== GL_RGBA
||
455 textureBaseFormat
== GL_RGB
||
456 textureBaseFormat
== GL_RG
||
457 textureBaseFormat
== GL_RED
||
458 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
459 textureBaseFormat
== GL_LUMINANCE
||
460 textureBaseFormat
== GL_ALPHA
);
462 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
463 * components
* sizeof(GLuint
));
468 for (img
= 0; img
< srcDepth
; img
++) {
470 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
474 for (row
= 0; row
< srcHeight
; row
++) {
475 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
476 dst
, srcFormat
, srcType
, src
,
478 dst
+= srcWidth
* components
;
483 if (logicalBaseFormat
!= textureBaseFormat
) {
485 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
486 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
491 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
492 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
493 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
495 /* The actual texture format should have at least as many components
496 * as the logical texture format.
498 ASSERT(texComponents
>= logComponents
);
500 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
501 * texComponents
* sizeof(GLuint
));
507 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
509 n
= srcWidth
* srcHeight
* srcDepth
;
510 for (i
= 0; i
< n
; i
++) {
512 for (k
= 0; k
< texComponents
; k
++) {
515 newImage
[i
* texComponents
+ k
] = 0.0F
;
517 newImage
[i
* texComponents
+ k
] = 1.0F
;
519 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
524 tempImage
= newImage
;
533 * Make a temporary (color) texture image with GLchan components.
534 * Apply all needed pixel unpacking and pixel transfer operations.
535 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
536 * Suppose the user specifies GL_LUMINANCE as the internal texture format
537 * but the graphics hardware doesn't support luminance textures. So, we might
538 * use an RGB hardware format instead.
539 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
541 * \param ctx the rendering context
542 * \param dims image dimensions: 1, 2 or 3
543 * \param logicalBaseFormat basic texture derived from the user's
544 * internal texture format value
545 * \param textureBaseFormat the actual basic format of the texture
546 * \param srcWidth source image width
547 * \param srcHeight source image height
548 * \param srcDepth source image depth
549 * \param srcFormat source image format
550 * \param srcType source image type
551 * \param srcAddr source image address
552 * \param srcPacking source image pixel packing
553 * \return resulting image with format = textureBaseFormat and type = GLchan.
556 _mesa_make_temp_chan_image(struct gl_context
*ctx
, GLuint dims
,
557 GLenum logicalBaseFormat
,
558 GLenum textureBaseFormat
,
559 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
560 GLenum srcFormat
, GLenum srcType
,
561 const GLvoid
*srcAddr
,
562 const struct gl_pixelstore_attrib
*srcPacking
)
564 GLuint transferOps
= ctx
->_ImageTransferState
;
565 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
567 GLchan
*tempImage
, *dst
;
569 ASSERT(dims
>= 1 && dims
<= 3);
571 ASSERT(logicalBaseFormat
== GL_RGBA
||
572 logicalBaseFormat
== GL_RGB
||
573 logicalBaseFormat
== GL_RG
||
574 logicalBaseFormat
== GL_RED
||
575 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
576 logicalBaseFormat
== GL_LUMINANCE
||
577 logicalBaseFormat
== GL_ALPHA
||
578 logicalBaseFormat
== GL_INTENSITY
);
580 ASSERT(textureBaseFormat
== GL_RGBA
||
581 textureBaseFormat
== GL_RGB
||
582 textureBaseFormat
== GL_RG
||
583 textureBaseFormat
== GL_RED
||
584 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
585 textureBaseFormat
== GL_LUMINANCE
||
586 textureBaseFormat
== GL_ALPHA
||
587 textureBaseFormat
== GL_INTENSITY
);
589 /* unpack and transfer the source image */
590 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
591 * components
* sizeof(GLchan
));
597 for (img
= 0; img
< srcDepth
; img
++) {
598 const GLint srcStride
=
599 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
601 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
605 for (row
= 0; row
< srcHeight
; row
++) {
606 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
607 srcFormat
, srcType
, src
, srcPacking
,
609 dst
+= srcWidth
* components
;
614 if (logicalBaseFormat
!= textureBaseFormat
) {
615 /* one more conversion step */
616 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
617 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
622 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
623 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
624 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
626 /* The actual texture format should have at least as many components
627 * as the logical texture format.
629 ASSERT(texComponents
>= logComponents
);
631 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
632 * texComponents
* sizeof(GLchan
));
638 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
640 n
= srcWidth
* srcHeight
* srcDepth
;
641 for (i
= 0; i
< n
; i
++) {
643 for (k
= 0; k
< texComponents
; k
++) {
646 newImage
[i
* texComponents
+ k
] = 0;
648 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
650 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
655 tempImage
= newImage
;
663 * Copy GLubyte pixels from <src> to <dst> with swizzling.
664 * \param dst destination pixels
665 * \param dstComponents number of color components in destination pixels
666 * \param src source pixels
667 * \param srcComponents number of color components in source pixels
668 * \param map the swizzle mapping. map[X] says where to find the X component
669 * in the source image's pixels. For example, if the source image
670 * is GL_BGRA and X = red, map[0] yields 2.
671 * \param count number of pixels to copy/swizzle.
674 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
675 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
677 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
680 for (i = 0; i < count; i++) { \
682 if (srcComps == 4) { \
683 COPY_4UBV(tmp, src); \
686 for (j = 0; j < srcComps; j++) { \
691 for (j = 0; j < dstComps; j++) { \
692 dst[j] = tmp[map[j]]; \
703 ASSERT(srcComponents
<= 4);
704 ASSERT(dstComponents
<= 4);
706 switch (dstComponents
) {
708 switch (srcComponents
) {
710 SWZ_CPY(dst
, src
, count
, 4, 4);
713 SWZ_CPY(dst
, src
, count
, 4, 3);
716 SWZ_CPY(dst
, src
, count
, 4, 2);
719 SWZ_CPY(dst
, src
, count
, 4, 1);
726 switch (srcComponents
) {
728 SWZ_CPY(dst
, src
, count
, 3, 4);
731 SWZ_CPY(dst
, src
, count
, 3, 3);
734 SWZ_CPY(dst
, src
, count
, 3, 2);
737 SWZ_CPY(dst
, src
, count
, 3, 1);
744 switch (srcComponents
) {
746 SWZ_CPY(dst
, src
, count
, 2, 4);
749 SWZ_CPY(dst
, src
, count
, 2, 3);
752 SWZ_CPY(dst
, src
, count
, 2, 2);
755 SWZ_CPY(dst
, src
, count
, 2, 1);
762 switch (srcComponents
) {
764 SWZ_CPY(dst
, src
, count
, 1, 4);
767 SWZ_CPY(dst
, src
, count
, 1, 3);
770 SWZ_CPY(dst
, src
, count
, 1, 2);
773 SWZ_CPY(dst
, src
, count
, 1, 1);
787 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
788 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
792 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
793 * mapping array depending on endianness.
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
;
813 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
814 * mapping array depending on pixelstore byte swapping state.
816 static const GLubyte
*
817 byteswap_mapping( GLboolean swapBytes
,
825 case GL_UNSIGNED_BYTE
:
827 case GL_UNSIGNED_INT_8_8_8_8
:
828 case GL_UNSIGNED_INT_8_8_8_8_REV
:
838 * Transfer a GLubyte texture image with component swizzling.
841 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
846 GLenum baseInternalFormat
,
848 const GLubyte
*rgba2dst
,
849 GLuint dstComponents
,
852 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
854 const GLuint
*dstImageOffsets
,
856 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
857 const GLvoid
*srcAddr
,
858 const struct gl_pixelstore_attrib
*srcPacking
)
860 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
861 const GLubyte
*srctype2ubyte
, *swap
;
862 GLubyte map
[4], src2base
[6], base2rgba
[6];
864 const GLint srcRowStride
=
865 _mesa_image_row_stride(srcPacking
, srcWidth
,
866 srcFormat
, GL_UNSIGNED_BYTE
);
867 const GLint srcImageStride
868 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
870 const GLubyte
*srcImage
871 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
872 srcWidth
, srcHeight
, srcFormat
,
873 GL_UNSIGNED_BYTE
, 0, 0, 0);
877 /* Translate from src->baseInternal->GL_RGBA->dst. This will
878 * correctly deal with RGBA->RGB->RGBA conversions where the final
879 * A value must be 0xff regardless of the incoming alpha values.
881 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
882 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
883 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
884 srctype2ubyte
= type_mapping(srcType
);
887 for (i
= 0; i
< 4; i
++)
888 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
890 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
892 if (srcComponents
== dstComponents
&&
893 srcRowStride
== dstRowStride
&&
894 srcRowStride
== srcWidth
* srcComponents
&&
896 /* 1 and 2D images only */
897 GLubyte
*dstImage
= (GLubyte
*) dstAddr
898 + dstYoffset
* dstRowStride
899 + dstXoffset
* dstComponents
;
900 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
901 srcWidth
* srcHeight
);
905 for (img
= 0; img
< srcDepth
; img
++) {
906 const GLubyte
*srcRow
= srcImage
;
907 GLubyte
*dstRow
= (GLubyte
*) dstAddr
908 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
909 + dstYoffset
* dstRowStride
910 + dstXoffset
* dstComponents
;
911 for (row
= 0; row
< srcHeight
; row
++) {
912 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
913 dstRow
+= dstRowStride
;
914 srcRow
+= srcRowStride
;
916 srcImage
+= srcImageStride
;
923 * Teximage storage routine for when a simple memcpy will do.
924 * No pixel transfer operations or special texel encodings allowed.
925 * 1D, 2D and 3D images supported.
928 memcpy_texture(struct gl_context
*ctx
,
932 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
934 const GLuint
*dstImageOffsets
,
935 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
936 GLenum srcFormat
, GLenum srcType
,
937 const GLvoid
*srcAddr
,
938 const struct gl_pixelstore_attrib
*srcPacking
)
940 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
942 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
943 srcWidth
, srcHeight
, srcFormat
, srcType
);
944 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
945 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
946 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
947 const GLint bytesPerRow
= srcWidth
* texelBytes
;
950 /* XXX update/re-enable for dstImageOffsets array */
951 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
952 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
953 GLubyte
*dstImage
= (GLubyte
*) dstAddr
954 + dstZoffset
* dstImageStride
955 + dstYoffset
* dstRowStride
956 + dstXoffset
* texelBytes
;
958 if (dstRowStride
== srcRowStride
&&
959 dstRowStride
== bytesPerRow
&&
960 ((dstImageStride
== srcImageStride
&&
961 dstImageStride
== bytesPerImage
) ||
964 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
969 for (img
= 0; img
< srcDepth
; img
++) {
970 const GLubyte
*srcRow
= srcImage
;
971 GLubyte
*dstRow
= dstImage
;
972 for (row
= 0; row
< srcHeight
; row
++) {
973 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
974 dstRow
+= dstRowStride
;
975 srcRow
+= srcRowStride
;
977 srcImage
+= srcImageStride
;
978 dstImage
+= dstImageStride
;
984 for (img
= 0; img
< srcDepth
; img
++) {
985 const GLubyte
*srcRow
= srcImage
;
986 GLubyte
*dstRow
= (GLubyte
*) dstAddr
987 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
988 + dstYoffset
* dstRowStride
989 + dstXoffset
* texelBytes
;
990 for (row
= 0; row
< srcHeight
; row
++) {
991 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
992 dstRow
+= dstRowStride
;
993 srcRow
+= srcRowStride
;
995 srcImage
+= srcImageStride
;
1002 * Store a 32-bit integer depth component texture image.
1005 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1007 const GLuint depthScale
= 0xffffffff;
1008 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1010 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1011 ASSERT(texelBytes
== sizeof(GLuint
));
1013 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1014 ctx
->Pixel
.DepthBias
== 0.0f
&&
1015 !srcPacking
->SwapBytes
&&
1016 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1017 srcFormat
== GL_DEPTH_COMPONENT
&&
1018 srcType
== GL_UNSIGNED_INT
) {
1019 /* simple memcpy path */
1020 memcpy_texture(ctx
, dims
,
1021 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1024 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1025 srcAddr
, srcPacking
);
1030 for (img
= 0; img
< srcDepth
; img
++) {
1031 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1032 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1033 + dstYoffset
* dstRowStride
1034 + dstXoffset
* texelBytes
;
1035 for (row
= 0; row
< srcHeight
; row
++) {
1036 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1037 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1038 _mesa_unpack_depth_span(ctx
, srcWidth
,
1039 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1040 depthScale
, srcType
, src
, srcPacking
);
1041 dstRow
+= dstRowStride
;
1050 * Store a 24-bit integer depth component texture image.
1053 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1055 const GLuint depthScale
= 0xffffff;
1056 const GLuint texelBytes
= 4;
1059 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1064 for (img
= 0; img
< srcDepth
; img
++) {
1065 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1066 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1067 + dstYoffset
* dstRowStride
1068 + dstXoffset
* texelBytes
;
1069 for (row
= 0; row
< srcHeight
; row
++) {
1070 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1071 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1072 _mesa_unpack_depth_span(ctx
, srcWidth
,
1073 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1074 depthScale
, srcType
, src
, srcPacking
);
1075 dstRow
+= dstRowStride
;
1084 * Store a 24-bit integer depth component texture image.
1087 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1089 const GLuint depthScale
= 0xffffff;
1090 const GLuint texelBytes
= 4;
1093 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1098 for (img
= 0; img
< srcDepth
; img
++) {
1099 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1100 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1101 + dstYoffset
* dstRowStride
1102 + dstXoffset
* texelBytes
;
1103 for (row
= 0; row
< srcHeight
; row
++) {
1104 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1105 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1106 GLuint
*dst
= (GLuint
*) dstRow
;
1108 _mesa_unpack_depth_span(ctx
, srcWidth
,
1109 GL_UNSIGNED_INT
, dst
,
1110 depthScale
, srcType
, src
, srcPacking
);
1111 for (i
= 0; i
< srcWidth
; i
++)
1113 dstRow
+= dstRowStride
;
1122 * Store a 16-bit integer depth component texture image.
1125 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1127 const GLuint depthScale
= 0xffff;
1128 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1130 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1131 ASSERT(texelBytes
== sizeof(GLushort
));
1133 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1134 ctx
->Pixel
.DepthBias
== 0.0f
&&
1135 !srcPacking
->SwapBytes
&&
1136 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1137 srcFormat
== GL_DEPTH_COMPONENT
&&
1138 srcType
== GL_UNSIGNED_SHORT
) {
1139 /* simple memcpy path */
1140 memcpy_texture(ctx
, dims
,
1141 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1144 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1145 srcAddr
, srcPacking
);
1150 for (img
= 0; img
< srcDepth
; img
++) {
1151 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1152 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1153 + dstYoffset
* dstRowStride
1154 + dstXoffset
* texelBytes
;
1155 for (row
= 0; row
< srcHeight
; row
++) {
1156 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1157 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1158 GLushort
*dst16
= (GLushort
*) dstRow
;
1159 _mesa_unpack_depth_span(ctx
, srcWidth
,
1160 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1161 srcType
, src
, srcPacking
);
1162 dstRow
+= dstRowStride
;
1171 * Store an rgb565 or rgb565_rev texture image.
1174 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1176 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1177 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1179 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1180 dstFormat
== MESA_FORMAT_RGB565_REV
);
1181 ASSERT(texelBytes
== 2);
1183 if (!ctx
->_ImageTransferState
&&
1184 !srcPacking
->SwapBytes
&&
1185 dstFormat
== MESA_FORMAT_RGB565
&&
1186 baseInternalFormat
== GL_RGB
&&
1187 srcFormat
== GL_RGB
&&
1188 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1189 /* simple memcpy path */
1190 memcpy_texture(ctx
, dims
,
1191 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1194 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1195 srcAddr
, srcPacking
);
1197 else if (!ctx
->_ImageTransferState
&&
1198 !srcPacking
->SwapBytes
&&
1199 baseInternalFormat
== GL_RGB
&&
1200 srcFormat
== GL_RGB
&&
1201 srcType
== GL_UNSIGNED_BYTE
&&
1203 /* do optimized tex store */
1204 const GLint srcRowStride
=
1205 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1206 const GLubyte
*src
= (const GLubyte
*)
1207 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1208 srcFormat
, srcType
, 0, 0, 0);
1209 GLubyte
*dst
= (GLubyte
*) dstAddr
1210 + dstYoffset
* dstRowStride
1211 + dstXoffset
* texelBytes
;
1213 for (row
= 0; row
< srcHeight
; row
++) {
1214 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1215 GLushort
*dstUS
= (GLushort
*) dst
;
1216 /* check for byteswapped format */
1217 if (dstFormat
== MESA_FORMAT_RGB565
) {
1218 for (col
= 0; col
< srcWidth
; col
++) {
1219 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1224 for (col
= 0; col
< srcWidth
; col
++) {
1225 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1229 dst
+= dstRowStride
;
1230 src
+= srcRowStride
;
1235 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1238 srcWidth
, srcHeight
, srcDepth
,
1239 srcFormat
, srcType
, srcAddr
,
1241 const GLchan
*src
= tempImage
;
1242 GLint img
, row
, col
;
1245 for (img
= 0; img
< srcDepth
; img
++) {
1246 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1247 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1248 + dstYoffset
* dstRowStride
1249 + dstXoffset
* texelBytes
;
1250 for (row
= 0; row
< srcHeight
; row
++) {
1251 GLushort
*dstUS
= (GLushort
*) dstRow
;
1252 /* check for byteswapped format */
1253 if (dstFormat
== MESA_FORMAT_RGB565
) {
1254 for (col
= 0; col
< srcWidth
; col
++) {
1255 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1256 CHAN_TO_UBYTE(src
[GCOMP
]),
1257 CHAN_TO_UBYTE(src
[BCOMP
]) );
1262 for (col
= 0; col
< srcWidth
; col
++) {
1263 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1264 CHAN_TO_UBYTE(src
[GCOMP
]),
1265 CHAN_TO_UBYTE(src
[BCOMP
]) );
1269 dstRow
+= dstRowStride
;
1272 free((void *) tempImage
);
1279 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1282 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1284 const GLboolean littleEndian
= _mesa_little_endian();
1285 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1286 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1288 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1289 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1290 ASSERT(texelBytes
== 4);
1292 if (!ctx
->_ImageTransferState
&&
1293 !srcPacking
->SwapBytes
&&
1294 dstFormat
== MESA_FORMAT_RGBA8888
&&
1295 baseInternalFormat
== GL_RGBA
&&
1296 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1297 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1298 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1299 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1300 /* simple memcpy path */
1301 memcpy_texture(ctx
, dims
,
1302 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1305 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1306 srcAddr
, srcPacking
);
1308 else if (!ctx
->_ImageTransferState
&&
1309 !srcPacking
->SwapBytes
&&
1310 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1311 baseInternalFormat
== GL_RGBA
&&
1312 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1313 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1314 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1315 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1316 /* simple memcpy path */
1317 memcpy_texture(ctx
, dims
,
1318 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1321 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1322 srcAddr
, srcPacking
);
1324 else if (!ctx
->_ImageTransferState
&&
1325 (srcType
== GL_UNSIGNED_BYTE
||
1326 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1327 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1328 can_swizzle(baseInternalFormat
) &&
1329 can_swizzle(srcFormat
)) {
1333 /* dstmap - how to swizzle from RGBA to dst format:
1335 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1336 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1349 _mesa_swizzle_ubyte_image(ctx
, dims
,
1354 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1355 dstRowStride
, dstImageOffsets
,
1356 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1361 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1364 srcWidth
, srcHeight
, srcDepth
,
1365 srcFormat
, srcType
, srcAddr
,
1367 const GLchan
*src
= tempImage
;
1368 GLint img
, row
, col
;
1371 for (img
= 0; img
< srcDepth
; img
++) {
1372 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1373 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1374 + dstYoffset
* dstRowStride
1375 + dstXoffset
* texelBytes
;
1376 for (row
= 0; row
< srcHeight
; row
++) {
1377 GLuint
*dstUI
= (GLuint
*) dstRow
;
1378 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1379 for (col
= 0; col
< srcWidth
; col
++) {
1380 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1381 CHAN_TO_UBYTE(src
[GCOMP
]),
1382 CHAN_TO_UBYTE(src
[BCOMP
]),
1383 CHAN_TO_UBYTE(src
[ACOMP
]) );
1388 for (col
= 0; col
< srcWidth
; col
++) {
1389 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1390 CHAN_TO_UBYTE(src
[GCOMP
]),
1391 CHAN_TO_UBYTE(src
[BCOMP
]),
1392 CHAN_TO_UBYTE(src
[ACOMP
]) );
1396 dstRow
+= dstRowStride
;
1399 free((void *) tempImage
);
1406 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1408 const GLboolean littleEndian
= _mesa_little_endian();
1409 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1410 const GLenum baseFormat
= GL_RGBA
;
1412 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1413 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1414 dstFormat
== MESA_FORMAT_XRGB8888
||
1415 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1416 ASSERT(texelBytes
== 4);
1418 if (!ctx
->_ImageTransferState
&&
1419 !srcPacking
->SwapBytes
&&
1420 (dstFormat
== MESA_FORMAT_ARGB8888
||
1421 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1422 baseInternalFormat
== GL_RGBA
&&
1423 srcFormat
== GL_BGRA
&&
1424 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1425 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1426 /* simple memcpy path (little endian) */
1427 memcpy_texture(ctx
, dims
,
1428 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1431 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1432 srcAddr
, srcPacking
);
1434 else if (!ctx
->_ImageTransferState
&&
1435 !srcPacking
->SwapBytes
&&
1436 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1437 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1438 baseInternalFormat
== GL_RGBA
&&
1439 srcFormat
== GL_BGRA
&&
1440 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1441 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1442 /* simple memcpy path (big endian) */
1443 memcpy_texture(ctx
, dims
,
1444 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1447 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1448 srcAddr
, srcPacking
);
1450 else if (!ctx
->_ImageTransferState
&&
1451 !srcPacking
->SwapBytes
&&
1452 (dstFormat
== MESA_FORMAT_ARGB8888
||
1453 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1454 srcFormat
== GL_RGB
&&
1455 (baseInternalFormat
== GL_RGBA
||
1456 baseInternalFormat
== GL_RGB
) &&
1457 srcType
== GL_UNSIGNED_BYTE
) {
1459 for (img
= 0; img
< srcDepth
; img
++) {
1460 const GLint srcRowStride
=
1461 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1462 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1463 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1464 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1465 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1466 + dstYoffset
* dstRowStride
1467 + dstXoffset
* texelBytes
;
1468 for (row
= 0; row
< srcHeight
; row
++) {
1469 GLuint
*d4
= (GLuint
*) dstRow
;
1470 for (col
= 0; col
< srcWidth
; col
++) {
1471 d4
[col
] = PACK_COLOR_8888(0xff,
1472 srcRow
[col
* 3 + RCOMP
],
1473 srcRow
[col
* 3 + GCOMP
],
1474 srcRow
[col
* 3 + BCOMP
]);
1476 dstRow
+= dstRowStride
;
1477 srcRow
+= srcRowStride
;
1481 else if (!ctx
->_ImageTransferState
&&
1482 !srcPacking
->SwapBytes
&&
1483 dstFormat
== MESA_FORMAT_ARGB8888
&&
1484 srcFormat
== GL_RGBA
&&
1485 baseInternalFormat
== GL_RGBA
&&
1486 srcType
== GL_UNSIGNED_BYTE
) {
1487 /* same as above case, but src data has alpha too */
1488 GLint img
, row
, col
;
1489 /* For some reason, streaming copies to write-combined regions
1490 * are extremely sensitive to the characteristics of how the
1491 * source data is retrieved. By reordering the source reads to
1492 * be in-order, the speed of this operation increases by half.
1493 * Strangely the same isn't required for the RGB path, above.
1495 for (img
= 0; img
< srcDepth
; img
++) {
1496 const GLint srcRowStride
=
1497 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1498 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1499 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1500 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1501 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1502 + dstYoffset
* dstRowStride
1503 + dstXoffset
* texelBytes
;
1504 for (row
= 0; row
< srcHeight
; row
++) {
1505 GLuint
*d4
= (GLuint
*) dstRow
;
1506 for (col
= 0; col
< srcWidth
; col
++) {
1507 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1508 srcRow
[col
* 4 + RCOMP
],
1509 srcRow
[col
* 4 + GCOMP
],
1510 srcRow
[col
* 4 + BCOMP
]);
1512 dstRow
+= dstRowStride
;
1513 srcRow
+= srcRowStride
;
1517 else if (!ctx
->_ImageTransferState
&&
1518 (srcType
== GL_UNSIGNED_BYTE
||
1519 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1520 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1521 can_swizzle(baseInternalFormat
) &&
1522 can_swizzle(srcFormat
)) {
1526 /* dstmap - how to swizzle from RGBA to dst format:
1528 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1529 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1530 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1531 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1532 dstmap
[3] = 3; /* alpha */
1533 dstmap
[2] = 0; /* red */
1534 dstmap
[1] = 1; /* green */
1535 dstmap
[0] = 2; /* blue */
1538 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1539 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1540 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1541 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1548 _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 for (img
= 0; img
< srcDepth
; img
++) {
1572 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1573 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1574 + dstYoffset
* dstRowStride
1575 + dstXoffset
* texelBytes
;
1576 for (row
= 0; row
< srcHeight
; row
++) {
1577 GLuint
*dstUI
= (GLuint
*) dstRow
;
1578 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1579 for (col
= 0; col
< srcWidth
; col
++) {
1580 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1581 CHAN_TO_UBYTE(src
[RCOMP
]),
1582 CHAN_TO_UBYTE(src
[GCOMP
]),
1583 CHAN_TO_UBYTE(src
[BCOMP
]) );
1587 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1588 for (col
= 0; col
< srcWidth
; col
++) {
1589 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1590 CHAN_TO_UBYTE(src
[RCOMP
]),
1591 CHAN_TO_UBYTE(src
[GCOMP
]),
1592 CHAN_TO_UBYTE(src
[BCOMP
]) );
1597 for (col
= 0; col
< srcWidth
; col
++) {
1598 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1599 CHAN_TO_UBYTE(src
[RCOMP
]),
1600 CHAN_TO_UBYTE(src
[GCOMP
]),
1601 CHAN_TO_UBYTE(src
[BCOMP
]) );
1605 dstRow
+= dstRowStride
;
1608 free((void *) tempImage
);
1615 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1617 const GLboolean littleEndian
= _mesa_little_endian();
1618 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1619 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1621 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1622 ASSERT(texelBytes
== 3);
1624 if (!ctx
->_ImageTransferState
&&
1625 !srcPacking
->SwapBytes
&&
1626 baseInternalFormat
== GL_RGB
&&
1627 srcFormat
== GL_BGR
&&
1628 srcType
== GL_UNSIGNED_BYTE
&&
1630 /* simple memcpy path */
1631 memcpy_texture(ctx
, dims
,
1632 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1635 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1636 srcAddr
, srcPacking
);
1638 else if (!ctx
->_ImageTransferState
&&
1639 !srcPacking
->SwapBytes
&&
1640 srcFormat
== GL_RGBA
&&
1641 srcType
== GL_UNSIGNED_BYTE
) {
1642 /* extract RGB from RGBA */
1643 GLint img
, row
, col
;
1644 for (img
= 0; img
< srcDepth
; img
++) {
1645 const GLint srcRowStride
=
1646 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1647 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1648 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1649 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1650 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1651 + dstYoffset
* dstRowStride
1652 + dstXoffset
* texelBytes
;
1653 for (row
= 0; row
< srcHeight
; row
++) {
1654 for (col
= 0; col
< srcWidth
; col
++) {
1655 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1656 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1657 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1659 dstRow
+= dstRowStride
;
1660 srcRow
+= srcRowStride
;
1664 else if (!ctx
->_ImageTransferState
&&
1665 srcType
== GL_UNSIGNED_BYTE
&&
1666 can_swizzle(baseInternalFormat
) &&
1667 can_swizzle(srcFormat
)) {
1671 /* dstmap - how to swizzle from RGBA to dst format:
1676 dstmap
[3] = ONE
; /* ? */
1678 _mesa_swizzle_ubyte_image(ctx
, dims
,
1683 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1684 dstRowStride
, dstImageOffsets
,
1685 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1690 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1693 srcWidth
, srcHeight
, srcDepth
,
1694 srcFormat
, srcType
, srcAddr
,
1696 const GLchan
*src
= (const GLchan
*) tempImage
;
1697 GLint img
, row
, col
;
1700 for (img
= 0; img
< srcDepth
; img
++) {
1701 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1702 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1703 + dstYoffset
* dstRowStride
1704 + dstXoffset
* texelBytes
;
1705 for (row
= 0; row
< srcHeight
; row
++) {
1708 for (col
= 0; col
< srcWidth
; col
++) {
1709 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1710 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1711 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1716 for (col
= 0; col
< srcWidth
; col
++) {
1717 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1718 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1719 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1724 for (col
= 0; col
< srcWidth
; col
++) {
1725 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1726 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1727 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1731 dstRow
+= dstRowStride
;
1734 free((void *) tempImage
);
1741 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1743 const GLboolean littleEndian
= _mesa_little_endian();
1744 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1745 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1747 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1748 ASSERT(texelBytes
== 3);
1750 if (!ctx
->_ImageTransferState
&&
1751 !srcPacking
->SwapBytes
&&
1752 baseInternalFormat
== GL_RGB
&&
1753 srcFormat
== GL_RGB
&&
1754 srcType
== GL_UNSIGNED_BYTE
&&
1756 /* simple memcpy path */
1757 memcpy_texture(ctx
, dims
,
1758 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1761 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1762 srcAddr
, srcPacking
);
1764 else if (!ctx
->_ImageTransferState
&&
1765 !srcPacking
->SwapBytes
&&
1766 srcFormat
== GL_RGBA
&&
1767 srcType
== GL_UNSIGNED_BYTE
) {
1768 /* extract BGR from RGBA */
1770 for (img
= 0; img
< srcDepth
; img
++) {
1771 const GLint srcRowStride
=
1772 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1773 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1774 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1775 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1776 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1777 + dstYoffset
* dstRowStride
1778 + dstXoffset
* texelBytes
;
1779 for (row
= 0; row
< srcHeight
; row
++) {
1780 for (col
= 0; col
< srcWidth
; col
++) {
1781 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1782 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1783 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1785 dstRow
+= dstRowStride
;
1786 srcRow
+= srcRowStride
;
1790 else if (!ctx
->_ImageTransferState
&&
1791 srcType
== GL_UNSIGNED_BYTE
&&
1792 can_swizzle(baseInternalFormat
) &&
1793 can_swizzle(srcFormat
)) {
1797 /* dstmap - how to swizzle from RGBA to dst format:
1802 dstmap
[3] = ONE
; /* ? */
1804 _mesa_swizzle_ubyte_image(ctx
, dims
,
1809 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1810 dstRowStride
, dstImageOffsets
,
1811 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1816 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1819 srcWidth
, srcHeight
, srcDepth
,
1820 srcFormat
, srcType
, srcAddr
,
1822 const GLchan
*src
= (const GLchan
*) tempImage
;
1823 GLint img
, row
, col
;
1826 for (img
= 0; img
< srcDepth
; img
++) {
1827 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1828 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1829 + dstYoffset
* dstRowStride
1830 + dstXoffset
* texelBytes
;
1831 for (row
= 0; row
< srcHeight
; row
++) {
1832 for (col
= 0; col
< srcWidth
; col
++) {
1833 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1834 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1835 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1838 dstRow
+= dstRowStride
;
1841 free((void *) tempImage
);
1848 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1850 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1851 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1853 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1854 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1855 ASSERT(texelBytes
== 2);
1857 if (!ctx
->_ImageTransferState
&&
1858 !srcPacking
->SwapBytes
&&
1859 dstFormat
== MESA_FORMAT_ARGB4444
&&
1860 baseInternalFormat
== GL_RGBA
&&
1861 srcFormat
== GL_BGRA
&&
1862 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1863 /* simple memcpy path */
1864 memcpy_texture(ctx
, dims
,
1865 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1868 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1869 srcAddr
, srcPacking
);
1873 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1876 srcWidth
, srcHeight
, srcDepth
,
1877 srcFormat
, srcType
, srcAddr
,
1879 const GLchan
*src
= tempImage
;
1880 GLint img
, row
, col
;
1883 for (img
= 0; img
< srcDepth
; img
++) {
1884 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1885 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1886 + dstYoffset
* dstRowStride
1887 + dstXoffset
* texelBytes
;
1888 for (row
= 0; row
< srcHeight
; row
++) {
1889 GLushort
*dstUS
= (GLushort
*) dstRow
;
1890 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1891 for (col
= 0; col
< srcWidth
; col
++) {
1892 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1893 CHAN_TO_UBYTE(src
[RCOMP
]),
1894 CHAN_TO_UBYTE(src
[GCOMP
]),
1895 CHAN_TO_UBYTE(src
[BCOMP
]) );
1900 for (col
= 0; col
< srcWidth
; col
++) {
1901 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1902 CHAN_TO_UBYTE(src
[RCOMP
]),
1903 CHAN_TO_UBYTE(src
[GCOMP
]),
1904 CHAN_TO_UBYTE(src
[BCOMP
]) );
1908 dstRow
+= dstRowStride
;
1911 free((void *) tempImage
);
1917 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1919 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1920 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1922 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1923 ASSERT(texelBytes
== 2);
1925 if (!ctx
->_ImageTransferState
&&
1926 !srcPacking
->SwapBytes
&&
1927 dstFormat
== MESA_FORMAT_RGBA5551
&&
1928 baseInternalFormat
== GL_RGBA
&&
1929 srcFormat
== GL_RGBA
&&
1930 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1931 /* simple memcpy path */
1932 memcpy_texture(ctx
, dims
,
1933 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1936 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1937 srcAddr
, srcPacking
);
1941 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1944 srcWidth
, srcHeight
, srcDepth
,
1945 srcFormat
, srcType
, srcAddr
,
1947 const GLchan
*src
=tempImage
;
1948 GLint img
, row
, col
;
1951 for (img
= 0; img
< srcDepth
; img
++) {
1952 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1953 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1954 + dstYoffset
* dstRowStride
1955 + dstXoffset
* texelBytes
;
1956 for (row
= 0; row
< srcHeight
; row
++) {
1957 GLushort
*dstUS
= (GLushort
*) dstRow
;
1958 for (col
= 0; col
< srcWidth
; col
++) {
1959 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1960 CHAN_TO_UBYTE(src
[GCOMP
]),
1961 CHAN_TO_UBYTE(src
[BCOMP
]),
1962 CHAN_TO_UBYTE(src
[ACOMP
]) );
1965 dstRow
+= dstRowStride
;
1968 free((void *) tempImage
);
1974 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1976 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1977 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1979 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1980 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1981 ASSERT(texelBytes
== 2);
1983 if (!ctx
->_ImageTransferState
&&
1984 !srcPacking
->SwapBytes
&&
1985 dstFormat
== MESA_FORMAT_ARGB1555
&&
1986 baseInternalFormat
== GL_RGBA
&&
1987 srcFormat
== GL_BGRA
&&
1988 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1989 /* simple memcpy path */
1990 memcpy_texture(ctx
, dims
,
1991 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1994 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1995 srcAddr
, srcPacking
);
1999 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2002 srcWidth
, srcHeight
, srcDepth
,
2003 srcFormat
, srcType
, srcAddr
,
2005 const GLchan
*src
=tempImage
;
2006 GLint img
, row
, col
;
2009 for (img
= 0; img
< srcDepth
; img
++) {
2010 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2011 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2012 + dstYoffset
* dstRowStride
2013 + dstXoffset
* texelBytes
;
2014 for (row
= 0; row
< srcHeight
; row
++) {
2015 GLushort
*dstUS
= (GLushort
*) dstRow
;
2016 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2017 for (col
= 0; col
< srcWidth
; col
++) {
2018 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
2019 CHAN_TO_UBYTE(src
[RCOMP
]),
2020 CHAN_TO_UBYTE(src
[GCOMP
]),
2021 CHAN_TO_UBYTE(src
[BCOMP
]) );
2026 for (col
= 0; col
< srcWidth
; col
++) {
2027 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2028 CHAN_TO_UBYTE(src
[RCOMP
]),
2029 CHAN_TO_UBYTE(src
[GCOMP
]),
2030 CHAN_TO_UBYTE(src
[BCOMP
]) );
2034 dstRow
+= dstRowStride
;
2037 free((void *) tempImage
);
2044 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2046 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2047 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2049 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2050 ASSERT(texelBytes
== 4);
2052 if (!ctx
->_ImageTransferState
&&
2053 !srcPacking
->SwapBytes
&&
2054 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2055 srcFormat
== GL_BGRA
&&
2056 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2057 baseInternalFormat
== GL_RGBA
) {
2058 /* simple memcpy path */
2059 memcpy_texture(ctx
, dims
,
2060 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2063 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2064 srcAddr
, srcPacking
);
2068 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2071 srcWidth
, srcHeight
, srcDepth
,
2072 srcFormat
, srcType
, srcAddr
,
2074 ctx
->_ImageTransferState
);
2075 const GLfloat
*src
= tempImage
;
2076 GLint img
, row
, col
;
2079 for (img
= 0; img
< srcDepth
; img
++) {
2080 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2081 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2082 + dstYoffset
* dstRowStride
2083 + dstXoffset
* texelBytes
;
2084 if (baseInternalFormat
== GL_RGBA
) {
2085 for (row
= 0; row
< srcHeight
; row
++) {
2086 GLuint
*dstUI
= (GLuint
*) dstRow
;
2087 for (col
= 0; col
< srcWidth
; col
++) {
2090 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2091 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2092 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2093 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2094 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2097 dstRow
+= dstRowStride
;
2099 } else if (baseInternalFormat
== GL_RGB
) {
2100 for (row
= 0; row
< srcHeight
; row
++) {
2101 GLuint
*dstUI
= (GLuint
*) dstRow
;
2102 for (col
= 0; col
< srcWidth
; col
++) {
2105 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2106 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2107 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2108 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2111 dstRow
+= dstRowStride
;
2117 free((void *) tempImage
);
2124 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2127 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2129 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2130 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2132 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2133 ASSERT(texelBytes
== 1);
2137 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2140 srcWidth
, srcHeight
, srcDepth
,
2141 srcFormat
, srcType
, srcAddr
,
2143 const GLchan
*src
= tempImage
;
2144 GLint img
, row
, col
;
2147 for (img
= 0; img
< srcDepth
; img
++) {
2148 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2149 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2150 + dstYoffset
* dstRowStride
2151 + dstXoffset
* texelBytes
;
2152 for (row
= 0; row
< srcHeight
; row
++) {
2153 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2154 for (col
= 0; col
< srcWidth
; col
++) {
2155 /* src[0] is luminance, src[1] is alpha */
2156 dstUS
[col
] = PACK_COLOR_44( CHAN_TO_UBYTE(src
[1]),
2157 CHAN_TO_UBYTE(src
[0]) );
2160 dstRow
+= dstRowStride
;
2163 free((void *) tempImage
);
2170 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2173 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2175 const GLboolean littleEndian
= _mesa_little_endian();
2176 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2177 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2179 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2180 dstFormat
== MESA_FORMAT_AL88_REV
||
2181 dstFormat
== MESA_FORMAT_RG88
||
2182 dstFormat
== MESA_FORMAT_RG88_REV
);
2183 ASSERT(texelBytes
== 2);
2185 if (!ctx
->_ImageTransferState
&&
2186 !srcPacking
->SwapBytes
&&
2187 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
2188 baseInternalFormat
== srcFormat
&&
2189 srcType
== GL_UNSIGNED_BYTE
&&
2191 /* simple memcpy path */
2192 memcpy_texture(ctx
, dims
,
2193 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2196 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2197 srcAddr
, srcPacking
);
2199 else if (!ctx
->_ImageTransferState
&&
2201 srcType
== GL_UNSIGNED_BYTE
&&
2202 can_swizzle(baseInternalFormat
) &&
2203 can_swizzle(srcFormat
)) {
2206 /* dstmap - how to swizzle from RGBA to dst format:
2208 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2209 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2210 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2220 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2221 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2230 dstmap
[2] = ZERO
; /* ? */
2231 dstmap
[3] = ONE
; /* ? */
2233 _mesa_swizzle_ubyte_image(ctx
, dims
,
2238 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2239 dstRowStride
, dstImageOffsets
,
2240 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2245 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2248 srcWidth
, srcHeight
, srcDepth
,
2249 srcFormat
, srcType
, srcAddr
,
2251 const GLchan
*src
= tempImage
;
2252 GLint img
, row
, col
;
2255 for (img
= 0; img
< srcDepth
; img
++) {
2256 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2257 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2258 + dstYoffset
* dstRowStride
2259 + dstXoffset
* texelBytes
;
2260 for (row
= 0; row
< srcHeight
; row
++) {
2261 GLushort
*dstUS
= (GLushort
*) dstRow
;
2262 if (dstFormat
== MESA_FORMAT_AL88
||
2263 dstFormat
== MESA_FORMAT_RG88
) {
2264 for (col
= 0; col
< srcWidth
; col
++) {
2265 /* src[0] is luminance, src[1] is alpha */
2266 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2267 CHAN_TO_UBYTE(src
[0]) );
2272 for (col
= 0; col
< srcWidth
; col
++) {
2273 /* src[0] is luminance, src[1] is alpha */
2274 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2275 CHAN_TO_UBYTE(src
[0]) );
2279 dstRow
+= dstRowStride
;
2282 free((void *) tempImage
);
2289 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2292 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2294 const GLboolean littleEndian
= _mesa_little_endian();
2295 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2296 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2298 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2299 dstFormat
== MESA_FORMAT_AL1616_REV
||
2300 dstFormat
== MESA_FORMAT_RG1616
||
2301 dstFormat
== MESA_FORMAT_RG1616_REV
);
2302 ASSERT(texelBytes
== 4);
2304 if (!ctx
->_ImageTransferState
&&
2305 !srcPacking
->SwapBytes
&&
2306 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2307 baseInternalFormat
== srcFormat
&&
2308 srcType
== GL_UNSIGNED_SHORT
&&
2310 /* simple memcpy path */
2311 memcpy_texture(ctx
, dims
,
2312 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2315 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2316 srcAddr
, srcPacking
);
2320 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2323 srcWidth
, srcHeight
, srcDepth
,
2324 srcFormat
, srcType
, srcAddr
,
2326 ctx
->_ImageTransferState
);
2327 const GLfloat
*src
= tempImage
;
2328 GLint img
, row
, col
;
2331 for (img
= 0; img
< srcDepth
; img
++) {
2332 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2333 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2334 + dstYoffset
* dstRowStride
2335 + dstXoffset
* texelBytes
;
2336 for (row
= 0; row
< srcHeight
; row
++) {
2337 GLuint
*dstUI
= (GLuint
*) dstRow
;
2338 if (dstFormat
== MESA_FORMAT_AL1616
||
2339 dstFormat
== MESA_FORMAT_RG1616
) {
2340 for (col
= 0; col
< srcWidth
; col
++) {
2343 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2344 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2345 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2350 for (col
= 0; col
< srcWidth
; col
++) {
2353 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2354 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2355 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2359 dstRow
+= dstRowStride
;
2362 free((void *) tempImage
);
2368 /* Texstore for R16, A16, L16, I16. */
2370 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2372 const GLboolean littleEndian
= _mesa_little_endian();
2373 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2374 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2376 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2377 dstFormat
== MESA_FORMAT_A16
||
2378 dstFormat
== MESA_FORMAT_L16
||
2379 dstFormat
== MESA_FORMAT_I16
);
2380 ASSERT(texelBytes
== 2);
2382 if (!ctx
->_ImageTransferState
&&
2383 !srcPacking
->SwapBytes
&&
2384 baseInternalFormat
== srcFormat
&&
2385 srcType
== GL_UNSIGNED_SHORT
&&
2387 /* simple memcpy path */
2388 memcpy_texture(ctx
, dims
,
2389 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2392 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2393 srcAddr
, srcPacking
);
2397 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2400 srcWidth
, srcHeight
, srcDepth
,
2401 srcFormat
, srcType
, srcAddr
,
2403 ctx
->_ImageTransferState
);
2404 const GLfloat
*src
= tempImage
;
2405 GLint img
, row
, col
;
2408 for (img
= 0; img
< srcDepth
; img
++) {
2409 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2410 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2411 + dstYoffset
* dstRowStride
2412 + dstXoffset
* texelBytes
;
2413 for (row
= 0; row
< srcHeight
; row
++) {
2414 GLushort
*dstUS
= (GLushort
*) dstRow
;
2415 for (col
= 0; col
< srcWidth
; col
++) {
2418 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2422 dstRow
+= dstRowStride
;
2425 free((void *) tempImage
);
2432 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2434 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2435 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2437 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2438 ASSERT(texelBytes
== 8);
2440 if (!ctx
->_ImageTransferState
&&
2441 !srcPacking
->SwapBytes
&&
2442 baseInternalFormat
== GL_RGBA
&&
2443 srcFormat
== GL_RGBA
&&
2444 srcType
== GL_UNSIGNED_SHORT
) {
2445 /* simple memcpy path */
2446 memcpy_texture(ctx
, dims
,
2447 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2450 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2451 srcAddr
, srcPacking
);
2455 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2458 srcWidth
, srcHeight
, srcDepth
,
2459 srcFormat
, srcType
, srcAddr
,
2461 ctx
->_ImageTransferState
);
2462 const GLfloat
*src
= tempImage
;
2463 GLint img
, row
, col
;
2466 for (img
= 0; img
< srcDepth
; img
++) {
2467 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2468 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2469 + dstYoffset
* dstRowStride
2470 + dstXoffset
* texelBytes
;
2471 for (row
= 0; row
< srcHeight
; row
++) {
2472 GLushort
*dstUS
= (GLushort
*) dstRow
;
2473 for (col
= 0; col
< srcWidth
; col
++) {
2474 GLushort r
, g
, b
, a
;
2476 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2477 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2478 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2479 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2486 dstRow
+= dstRowStride
;
2489 free((void *) tempImage
);
2496 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2498 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2499 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2501 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R_16
||
2502 dstFormat
== MESA_FORMAT_SIGNED_RG_16
||
2503 dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2504 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2506 if (!ctx
->_ImageTransferState
&&
2507 !srcPacking
->SwapBytes
&&
2508 baseInternalFormat
== GL_RGBA
&&
2509 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2510 srcFormat
== GL_RGBA
&&
2511 srcType
== GL_SHORT
) {
2512 /* simple memcpy path */
2513 memcpy_texture(ctx
, dims
,
2514 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2517 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2518 srcAddr
, srcPacking
);
2522 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2525 srcWidth
, srcHeight
, srcDepth
,
2526 srcFormat
, srcType
, srcAddr
,
2528 ctx
->_ImageTransferState
);
2529 const GLfloat
*src
= tempImage
;
2530 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2531 GLint img
, row
, col
;
2536 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2537 * 3 or 4 components/pixel here.
2539 for (img
= 0; img
< srcDepth
; img
++) {
2540 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2541 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2542 + dstYoffset
* dstRowStride
2543 + dstXoffset
* texelBytes
;
2544 for (row
= 0; row
< srcHeight
; row
++) {
2545 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2546 for (col
= 0; col
< srcWidth
; col
++) {
2548 for (c
= 0; c
< comps
; c
++) {
2550 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2551 dstRowS
[col
* comps
+ c
] = p
;
2554 dstRow
+= dstRowStride
;
2555 src
+= 4 * srcWidth
;
2558 free((void *) tempImage
);
2565 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2567 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2568 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2570 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2571 ASSERT(texelBytes
== 1);
2573 if (!ctx
->_ImageTransferState
&&
2574 !srcPacking
->SwapBytes
&&
2575 baseInternalFormat
== GL_RGB
&&
2576 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2577 /* simple memcpy path */
2578 memcpy_texture(ctx
, dims
,
2579 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2582 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2583 srcAddr
, srcPacking
);
2587 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2590 srcWidth
, srcHeight
, srcDepth
,
2591 srcFormat
, srcType
, srcAddr
,
2593 const GLchan
*src
= tempImage
;
2594 GLint img
, row
, col
;
2597 for (img
= 0; img
< srcDepth
; img
++) {
2598 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2599 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2600 + dstYoffset
* dstRowStride
2601 + dstXoffset
* texelBytes
;
2602 for (row
= 0; row
< srcHeight
; row
++) {
2603 for (col
= 0; col
< srcWidth
; col
++) {
2604 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2605 CHAN_TO_UBYTE(src
[GCOMP
]),
2606 CHAN_TO_UBYTE(src
[BCOMP
]) );
2609 dstRow
+= dstRowStride
;
2612 free((void *) tempImage
);
2619 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2622 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2624 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2625 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2627 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2628 dstFormat
== MESA_FORMAT_L8
||
2629 dstFormat
== MESA_FORMAT_I8
||
2630 dstFormat
== MESA_FORMAT_R8
);
2631 ASSERT(texelBytes
== 1);
2633 if (!ctx
->_ImageTransferState
&&
2634 !srcPacking
->SwapBytes
&&
2635 baseInternalFormat
== srcFormat
&&
2636 srcType
== GL_UNSIGNED_BYTE
) {
2637 /* simple memcpy path */
2638 memcpy_texture(ctx
, dims
,
2639 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2642 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2643 srcAddr
, srcPacking
);
2645 else if (!ctx
->_ImageTransferState
&&
2646 srcType
== GL_UNSIGNED_BYTE
&&
2647 can_swizzle(baseInternalFormat
) &&
2648 can_swizzle(srcFormat
)) {
2651 /* dstmap - how to swizzle from RGBA to dst format:
2653 if (dstFormat
== MESA_FORMAT_A8
) {
2659 dstmap
[1] = ZERO
; /* ? */
2660 dstmap
[2] = ZERO
; /* ? */
2661 dstmap
[3] = ONE
; /* ? */
2663 _mesa_swizzle_ubyte_image(ctx
, dims
,
2668 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2669 dstRowStride
, dstImageOffsets
,
2670 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2675 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2678 srcWidth
, srcHeight
, srcDepth
,
2679 srcFormat
, srcType
, srcAddr
,
2681 const GLchan
*src
= tempImage
;
2682 GLint img
, row
, col
;
2685 for (img
= 0; img
< srcDepth
; img
++) {
2686 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2687 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2688 + dstYoffset
* dstRowStride
2689 + dstXoffset
* texelBytes
;
2690 for (row
= 0; row
< srcHeight
; row
++) {
2691 for (col
= 0; col
< srcWidth
; col
++) {
2692 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2694 dstRow
+= dstRowStride
;
2698 free((void *) tempImage
);
2706 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2708 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2710 (void) dims
; (void) baseInternalFormat
;
2711 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2712 ASSERT(texelBytes
== 1);
2713 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2715 if (!ctx
->_ImageTransferState
&&
2716 !srcPacking
->SwapBytes
&&
2717 srcFormat
== GL_COLOR_INDEX
&&
2718 srcType
== GL_UNSIGNED_BYTE
) {
2719 /* simple memcpy path */
2720 memcpy_texture(ctx
, dims
,
2721 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2724 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2725 srcAddr
, srcPacking
);
2730 for (img
= 0; img
< srcDepth
; img
++) {
2731 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2732 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2733 + dstYoffset
* dstRowStride
2734 + dstXoffset
* texelBytes
;
2735 for (row
= 0; row
< srcHeight
; row
++) {
2736 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2737 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2738 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2739 srcType
, src
, srcPacking
,
2740 ctx
->_ImageTransferState
);
2741 dstRow
+= dstRowStride
;
2750 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2753 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2755 const GLboolean littleEndian
= _mesa_little_endian();
2756 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2758 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2760 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2761 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2762 ASSERT(texelBytes
== 2);
2763 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2764 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2765 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2766 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2767 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2769 /* always just memcpy since no pixel transfer ops apply */
2770 memcpy_texture(ctx
, dims
,
2771 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2774 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2775 srcAddr
, srcPacking
);
2777 /* Check if we need byte swapping */
2778 /* XXX the logic here _might_ be wrong */
2779 if (srcPacking
->SwapBytes
^
2780 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2781 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2784 for (img
= 0; img
< srcDepth
; img
++) {
2785 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2786 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2787 + dstYoffset
* dstRowStride
2788 + dstXoffset
* texelBytes
;
2789 for (row
= 0; row
< srcHeight
; row
++) {
2790 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2791 dstRow
+= dstRowStride
;
2799 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2801 const GLboolean littleEndian
= _mesa_little_endian();
2802 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2804 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2805 ASSERT(texelBytes
== 2);
2806 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2807 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2808 (srcFormat
== GL_DUDV_ATI
));
2809 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2811 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2813 /* simple memcpy path */
2814 memcpy_texture(ctx
, dims
,
2815 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2818 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2819 srcAddr
, srcPacking
);
2821 else if (srcType
== GL_BYTE
) {
2824 /* dstmap - how to swizzle from RGBA to dst format:
2834 dstmap
[2] = ZERO
; /* ? */
2835 dstmap
[3] = ONE
; /* ? */
2837 _mesa_swizzle_ubyte_image(ctx
, dims
,
2838 GL_LUMINANCE_ALPHA
, /* hack */
2839 GL_UNSIGNED_BYTE
, /* hack */
2840 GL_LUMINANCE_ALPHA
, /* hack */
2842 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2843 dstRowStride
, dstImageOffsets
,
2844 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2848 /* general path - note this is defined for 2d textures only */
2849 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2850 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2851 srcFormat
, srcType
);
2852 GLbyte
*tempImage
, *dst
, *src
;
2855 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2856 * components
* sizeof(GLbyte
));
2860 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2861 srcWidth
, srcHeight
,
2866 for (row
= 0; row
< srcHeight
; row
++) {
2867 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2868 dst
, srcFormat
, srcType
, src
,
2870 dst
+= srcWidth
* components
;
2875 dst
= (GLbyte
*) dstAddr
2876 + dstYoffset
* dstRowStride
2877 + dstXoffset
* texelBytes
;
2878 for (row
= 0; row
< srcHeight
; row
++) {
2879 memcpy(dst
, src
, srcWidth
* texelBytes
);
2880 dst
+= dstRowStride
;
2881 src
+= srcWidth
* texelBytes
;
2883 free((void *) tempImage
);
2890 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2893 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2895 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2896 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2898 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2899 ASSERT(texelBytes
== 1);
2901 /* XXX look at adding optimized paths */
2904 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2907 srcWidth
, srcHeight
, srcDepth
,
2908 srcFormat
, srcType
, srcAddr
,
2910 ctx
->_ImageTransferState
);
2911 const GLfloat
*srcRow
= tempImage
;
2912 GLint img
, row
, col
;
2915 for (img
= 0; img
< srcDepth
; img
++) {
2916 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2917 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2918 + dstYoffset
* dstRowStride
2919 + dstXoffset
* texelBytes
;
2920 for (row
= 0; row
< srcHeight
; row
++) {
2921 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2922 for (col
= 0; col
< srcWidth
; col
++) {
2923 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2925 dstRow
+= dstRowStride
;
2928 free((void *) tempImage
);
2935 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2938 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2940 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2941 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2943 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2944 ASSERT(texelBytes
== 1);
2946 /* XXX look at adding optimized paths */
2949 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2952 srcWidth
, srcHeight
, srcDepth
,
2953 srcFormat
, srcType
, srcAddr
,
2955 ctx
->_ImageTransferState
);
2956 const GLfloat
*srcRow
= tempImage
;
2957 GLint img
, row
, col
;
2960 for (img
= 0; img
< srcDepth
; img
++) {
2961 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2962 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2963 + dstYoffset
* dstRowStride
2964 + dstXoffset
* texelBytes
;
2965 for (row
= 0; row
< srcHeight
; row
++) {
2966 GLushort
*dstUS
= (GLushort
*) dstRow
;
2967 for (col
= 0; col
< srcWidth
; col
++) {
2968 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2969 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2971 dstRow
+= dstRowStride
;
2974 free((void *) tempImage
);
2981 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2984 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2986 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2987 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2989 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2990 ASSERT(texelBytes
== 4);
2994 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2997 srcWidth
, srcHeight
, srcDepth
,
2998 srcFormat
, srcType
, srcAddr
,
3000 ctx
->_ImageTransferState
);
3001 const GLfloat
*srcRow
= tempImage
;
3002 GLint img
, row
, col
;
3005 for (img
= 0; img
< srcDepth
; img
++) {
3006 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3007 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3008 + dstYoffset
* dstRowStride
3009 + dstXoffset
* texelBytes
;
3010 for (row
= 0; row
< srcHeight
; row
++) {
3011 GLuint
*dstUI
= (GLuint
*) dstRow
;
3012 for (col
= 0; col
< srcWidth
; col
++) {
3013 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3014 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3015 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3019 dstRow
+= dstRowStride
;
3022 free((void *) tempImage
);
3030 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3031 * MESA_FORMAT_SIGNED_RGBA8888_REV
3034 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3036 const GLboolean littleEndian
= _mesa_little_endian();
3037 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3038 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3040 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3041 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3042 ASSERT(texelBytes
== 4);
3044 if (!ctx
->_ImageTransferState
&&
3045 !srcPacking
->SwapBytes
&&
3046 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3047 baseInternalFormat
== GL_RGBA
&&
3048 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3049 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3050 /* simple memcpy path */
3051 memcpy_texture(ctx
, dims
,
3052 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3055 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3056 srcAddr
, srcPacking
);
3058 else if (!ctx
->_ImageTransferState
&&
3059 !srcPacking
->SwapBytes
&&
3060 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3061 baseInternalFormat
== GL_RGBA
&&
3062 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3063 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3064 /* simple memcpy path */
3065 memcpy_texture(ctx
, dims
,
3066 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3069 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3070 srcAddr
, srcPacking
);
3072 else if (!ctx
->_ImageTransferState
&&
3073 (srcType
== GL_BYTE
) &&
3074 can_swizzle(baseInternalFormat
) &&
3075 can_swizzle(srcFormat
)) {
3079 /* dstmap - how to swizzle from RGBA to dst format:
3081 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
3082 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
3095 _mesa_swizzle_ubyte_image(ctx
, dims
,
3100 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3101 dstRowStride
, dstImageOffsets
,
3102 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
3107 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3110 srcWidth
, srcHeight
, srcDepth
,
3111 srcFormat
, srcType
, srcAddr
,
3113 ctx
->_ImageTransferState
);
3114 const GLfloat
*srcRow
= tempImage
;
3115 GLint img
, row
, col
;
3118 for (img
= 0; img
< srcDepth
; img
++) {
3119 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3120 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3121 + dstYoffset
* dstRowStride
3122 + dstXoffset
* texelBytes
;
3123 for (row
= 0; row
< srcHeight
; row
++) {
3124 GLuint
*dstUI
= (GLuint
*) dstRow
;
3125 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3126 for (col
= 0; col
< srcWidth
; col
++) {
3127 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3128 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3129 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3130 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3135 for (col
= 0; col
< srcWidth
; col
++) {
3136 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3137 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3138 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3139 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3143 dstRow
+= dstRowStride
;
3146 free((void *) tempImage
);
3153 * Store a combined depth/stencil texture image.
3156 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3158 const GLuint depthScale
= 0xffffff;
3159 const GLint srcRowStride
3160 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3164 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3165 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
3166 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3168 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3169 ctx
->Pixel
.DepthBias
== 0.0f
&&
3170 !srcPacking
->SwapBytes
) {
3172 memcpy_texture(ctx
, dims
,
3173 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3176 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3177 srcAddr
, srcPacking
);
3179 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
3180 /* In case we only upload depth we need to preserve the stencil */
3181 for (img
= 0; img
< srcDepth
; img
++) {
3182 GLuint
*dstRow
= (GLuint
*) dstAddr
3183 + dstImageOffsets
[dstZoffset
+ img
]
3184 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3187 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3188 srcWidth
, srcHeight
,
3191 for (row
= 0; row
< srcHeight
; row
++) {
3192 GLuint depth
[MAX_WIDTH
];
3193 GLubyte stencil
[MAX_WIDTH
];
3195 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3197 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3198 keepstencil
= GL_TRUE
;
3200 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3201 keepdepth
= GL_TRUE
;
3204 if (keepdepth
== GL_FALSE
)
3205 /* the 24 depth bits will be in the low position: */
3206 _mesa_unpack_depth_span(ctx
, srcWidth
,
3207 GL_UNSIGNED_INT
, /* dst type */
3208 keepstencil
? depth
: dstRow
, /* dst addr */
3210 srcType
, src
, srcPacking
);
3212 if (keepstencil
== GL_FALSE
)
3213 /* get the 8-bit stencil values */
3214 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3215 GL_UNSIGNED_BYTE
, /* dst type */
3216 stencil
, /* dst addr */
3217 srcType
, src
, srcPacking
,
3218 ctx
->_ImageTransferState
);
3220 for (i
= 0; i
< srcWidth
; i
++) {
3222 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3224 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3227 src
+= srcRowStride
;
3228 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3237 * Store a combined depth/stencil texture image.
3240 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3242 const GLuint depthScale
= 0xffffff;
3243 const GLint srcRowStride
3244 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3248 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3249 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3250 srcFormat
== GL_DEPTH_COMPONENT
||
3251 srcFormat
== GL_STENCIL_INDEX
);
3252 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3253 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3255 for (img
= 0; img
< srcDepth
; img
++) {
3256 GLuint
*dstRow
= (GLuint
*) dstAddr
3257 + dstImageOffsets
[dstZoffset
+ img
]
3258 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3261 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3262 srcWidth
, srcHeight
,
3265 for (row
= 0; row
< srcHeight
; row
++) {
3266 GLuint depth
[MAX_WIDTH
];
3267 GLubyte stencil
[MAX_WIDTH
];
3269 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3271 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3272 keepstencil
= GL_TRUE
;
3274 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3275 keepdepth
= GL_TRUE
;
3278 if (keepdepth
== GL_FALSE
)
3279 /* the 24 depth bits will be in the low position: */
3280 _mesa_unpack_depth_span(ctx
, srcWidth
,
3281 GL_UNSIGNED_INT
, /* dst type */
3282 keepstencil
? depth
: dstRow
, /* dst addr */
3284 srcType
, src
, srcPacking
);
3286 if (keepstencil
== GL_FALSE
)
3287 /* get the 8-bit stencil values */
3288 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3289 GL_UNSIGNED_BYTE
, /* dst type */
3290 stencil
, /* dst addr */
3291 srcType
, src
, srcPacking
,
3292 ctx
->_ImageTransferState
);
3294 /* merge stencil values into depth values */
3295 for (i
= 0; i
< srcWidth
; i
++) {
3297 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3299 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3302 src
+= srcRowStride
;
3303 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3311 * Store simple 8-bit/value stencil texture data.
3314 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3316 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3317 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3319 if (!ctx
->_ImageTransferState
&&
3320 !srcPacking
->SwapBytes
&&
3321 baseInternalFormat
== srcFormat
&&
3322 srcType
== GL_UNSIGNED_BYTE
) {
3323 /* simple memcpy path */
3324 memcpy_texture(ctx
, dims
,
3325 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3328 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3329 srcAddr
, srcPacking
);
3332 const GLint srcRowStride
3333 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3337 for (img
= 0; img
< srcDepth
; img
++) {
3338 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3339 + dstImageOffsets
[dstZoffset
+ img
]
3340 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3343 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3344 srcWidth
, srcHeight
,
3347 for (row
= 0; row
< srcHeight
; row
++) {
3348 GLubyte stencil
[MAX_WIDTH
];
3351 /* get the 8-bit stencil values */
3352 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3353 GL_UNSIGNED_BYTE
, /* dst type */
3354 stencil
, /* dst addr */
3355 srcType
, src
, srcPacking
,
3356 ctx
->_ImageTransferState
);
3357 /* merge stencil values into depth values */
3358 for (i
= 0; i
< srcWidth
; i
++)
3359 dstRow
[i
] = stencil
[i
];
3361 src
+= srcRowStride
;
3362 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3373 * Store an image in any of the formats:
3374 * _mesa_texformat_rgba_float32
3375 * _mesa_texformat_rgb_float32
3376 * _mesa_texformat_alpha_float32
3377 * _mesa_texformat_luminance_float32
3378 * _mesa_texformat_luminance_alpha_float32
3379 * _mesa_texformat_intensity_float32
3382 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3384 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3385 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3386 const GLint components
= _mesa_components_in_format(baseFormat
);
3388 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3389 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3390 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3391 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3392 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3393 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3394 ASSERT(baseInternalFormat
== GL_RGBA
||
3395 baseInternalFormat
== GL_RGB
||
3396 baseInternalFormat
== GL_ALPHA
||
3397 baseInternalFormat
== GL_LUMINANCE
||
3398 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3399 baseInternalFormat
== GL_INTENSITY
);
3400 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3402 if (!ctx
->_ImageTransferState
&&
3403 !srcPacking
->SwapBytes
&&
3404 baseInternalFormat
== srcFormat
&&
3405 srcType
== GL_FLOAT
) {
3406 /* simple memcpy path */
3407 memcpy_texture(ctx
, dims
,
3408 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3411 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3412 srcAddr
, srcPacking
);
3416 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3419 srcWidth
, srcHeight
, srcDepth
,
3420 srcFormat
, srcType
, srcAddr
,
3422 ctx
->_ImageTransferState
);
3423 const GLfloat
*srcRow
= tempImage
;
3428 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3429 for (img
= 0; img
< srcDepth
; img
++) {
3430 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3431 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3432 + dstYoffset
* dstRowStride
3433 + dstXoffset
* texelBytes
;
3434 for (row
= 0; row
< srcHeight
; row
++) {
3435 memcpy(dstRow
, srcRow
, bytesPerRow
);
3436 dstRow
+= dstRowStride
;
3437 srcRow
+= srcWidth
* components
;
3441 free((void *) tempImage
);
3449 * As above, but store 16-bit floats.
3452 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3454 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3455 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3456 const GLint components
= _mesa_components_in_format(baseFormat
);
3458 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3459 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3460 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3461 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3462 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3463 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3464 ASSERT(baseInternalFormat
== GL_RGBA
||
3465 baseInternalFormat
== GL_RGB
||
3466 baseInternalFormat
== GL_ALPHA
||
3467 baseInternalFormat
== GL_LUMINANCE
||
3468 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3469 baseInternalFormat
== GL_INTENSITY
);
3470 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3472 if (!ctx
->_ImageTransferState
&&
3473 !srcPacking
->SwapBytes
&&
3474 baseInternalFormat
== srcFormat
&&
3475 srcType
== GL_HALF_FLOAT_ARB
) {
3476 /* simple memcpy path */
3477 memcpy_texture(ctx
, dims
,
3478 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3481 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3482 srcAddr
, srcPacking
);
3486 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3489 srcWidth
, srcHeight
, srcDepth
,
3490 srcFormat
, srcType
, srcAddr
,
3492 ctx
->_ImageTransferState
);
3493 const GLfloat
*src
= tempImage
;
3497 for (img
= 0; img
< srcDepth
; img
++) {
3498 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3499 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3500 + dstYoffset
* dstRowStride
3501 + dstXoffset
* texelBytes
;
3502 for (row
= 0; row
< srcHeight
; row
++) {
3503 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3505 for (i
= 0; i
< srcWidth
* components
; i
++) {
3506 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3508 dstRow
+= dstRowStride
;
3509 src
+= srcWidth
* components
;
3513 free((void *) tempImage
);
3519 /* non-normalized, signed int8 */
3521 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3523 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3524 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3525 const GLint components
= _mesa_components_in_format(baseFormat
);
3527 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3528 ASSERT(baseInternalFormat
== GL_RGBA
||
3529 baseInternalFormat
== GL_RGB
||
3530 baseInternalFormat
== GL_ALPHA
||
3531 baseInternalFormat
== GL_LUMINANCE
||
3532 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3533 baseInternalFormat
== GL_INTENSITY
);
3534 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3536 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3537 * to integer formats.
3539 if (!srcPacking
->SwapBytes
&&
3540 baseInternalFormat
== srcFormat
&&
3541 srcType
== GL_BYTE
) {
3542 /* simple memcpy path */
3543 memcpy_texture(ctx
, dims
,
3544 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3547 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3548 srcAddr
, srcPacking
);
3552 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3555 srcWidth
, srcHeight
, srcDepth
,
3556 srcFormat
, srcType
, srcAddr
,
3558 const GLfloat
*src
= tempImage
;
3562 for (img
= 0; img
< srcDepth
; img
++) {
3563 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3564 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3565 + dstYoffset
* dstRowStride
3566 + dstXoffset
* texelBytes
;
3567 for (row
= 0; row
< srcHeight
; row
++) {
3568 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3570 for (i
= 0; i
< srcWidth
* components
; i
++) {
3571 dstTexel
[i
] = (GLbyte
) src
[i
];
3573 dstRow
+= dstRowStride
;
3574 src
+= srcWidth
* components
;
3578 free((void *) tempImage
);
3584 /* non-normalized, signed int16 */
3586 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3588 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3589 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3590 const GLint components
= _mesa_components_in_format(baseFormat
);
3592 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3593 ASSERT(baseInternalFormat
== GL_RGBA
||
3594 baseInternalFormat
== GL_RGB
||
3595 baseInternalFormat
== GL_ALPHA
||
3596 baseInternalFormat
== GL_LUMINANCE
||
3597 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3598 baseInternalFormat
== GL_INTENSITY
);
3599 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3601 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3602 * to integer formats.
3604 if (!srcPacking
->SwapBytes
&&
3605 baseInternalFormat
== srcFormat
&&
3606 srcType
== GL_SHORT
) {
3607 /* simple memcpy path */
3608 memcpy_texture(ctx
, dims
,
3609 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3612 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3613 srcAddr
, srcPacking
);
3617 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3620 srcWidth
, srcHeight
, srcDepth
,
3621 srcFormat
, srcType
, srcAddr
,
3623 const GLfloat
*src
= tempImage
;
3627 for (img
= 0; img
< srcDepth
; img
++) {
3628 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3629 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3630 + dstYoffset
* dstRowStride
3631 + dstXoffset
* texelBytes
;
3632 for (row
= 0; row
< srcHeight
; row
++) {
3633 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3635 for (i
= 0; i
< srcWidth
* components
; i
++) {
3636 dstTexel
[i
] = (GLint
) src
[i
];
3638 dstRow
+= dstRowStride
;
3639 src
+= srcWidth
* components
;
3643 free((void *) tempImage
);
3649 /* non-normalized, signed int32 */
3651 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3653 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3654 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3655 const GLint components
= _mesa_components_in_format(baseFormat
);
3657 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3658 ASSERT(baseInternalFormat
== GL_RGBA
||
3659 baseInternalFormat
== GL_RGB
||
3660 baseInternalFormat
== GL_ALPHA
||
3661 baseInternalFormat
== GL_LUMINANCE
||
3662 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3663 baseInternalFormat
== GL_INTENSITY
);
3664 ASSERT(texelBytes
== components
* sizeof(GLint
));
3666 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3667 * to integer formats.
3669 if (!srcPacking
->SwapBytes
&&
3670 baseInternalFormat
== srcFormat
&&
3671 srcType
== GL_INT
) {
3672 /* simple memcpy path */
3673 memcpy_texture(ctx
, dims
,
3674 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3677 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3678 srcAddr
, srcPacking
);
3682 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3685 srcWidth
, srcHeight
, srcDepth
,
3686 srcFormat
, srcType
, srcAddr
,
3688 const GLfloat
*src
= tempImage
;
3692 for (img
= 0; img
< srcDepth
; img
++) {
3693 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3694 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3695 + dstYoffset
* dstRowStride
3696 + dstXoffset
* texelBytes
;
3697 for (row
= 0; row
< srcHeight
; row
++) {
3698 GLint
*dstTexel
= (GLint
*) dstRow
;
3700 for (i
= 0; i
< srcWidth
* components
; i
++) {
3701 dstTexel
[i
] = (GLint
) src
[i
];
3703 dstRow
+= dstRowStride
;
3704 src
+= srcWidth
* components
;
3708 free((void *) tempImage
);
3714 /* non-normalized, unsigned int8 */
3716 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3718 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3719 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3720 const GLint components
= _mesa_components_in_format(baseFormat
);
3722 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3723 ASSERT(baseInternalFormat
== GL_RGBA
||
3724 baseInternalFormat
== GL_RGB
||
3725 baseInternalFormat
== GL_ALPHA
||
3726 baseInternalFormat
== GL_LUMINANCE
||
3727 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3728 baseInternalFormat
== GL_INTENSITY
);
3729 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3731 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3732 * to integer formats.
3734 if (!srcPacking
->SwapBytes
&&
3735 baseInternalFormat
== srcFormat
&&
3736 srcType
== GL_UNSIGNED_BYTE
) {
3737 /* simple memcpy path */
3738 memcpy_texture(ctx
, dims
,
3739 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3742 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3743 srcAddr
, srcPacking
);
3747 const GLuint
*tempImage
=
3748 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3749 srcWidth
, srcHeight
, srcDepth
,
3750 srcFormat
, srcType
, srcAddr
, srcPacking
);
3751 const GLuint
*src
= tempImage
;
3755 for (img
= 0; img
< srcDepth
; img
++) {
3756 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3757 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3758 + dstYoffset
* dstRowStride
3759 + dstXoffset
* texelBytes
;
3760 for (row
= 0; row
< srcHeight
; row
++) {
3761 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3763 for (i
= 0; i
< srcWidth
* components
; i
++) {
3764 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3766 dstRow
+= dstRowStride
;
3767 src
+= srcWidth
* components
;
3771 free((void *) tempImage
);
3777 /* non-normalized, unsigned int16 */
3779 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3781 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3782 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3783 const GLint components
= _mesa_components_in_format(baseFormat
);
3785 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3786 ASSERT(baseInternalFormat
== GL_RGBA
||
3787 baseInternalFormat
== GL_RGB
||
3788 baseInternalFormat
== GL_ALPHA
||
3789 baseInternalFormat
== GL_LUMINANCE
||
3790 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3791 baseInternalFormat
== GL_INTENSITY
);
3792 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3794 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3795 * to integer formats.
3797 if (!srcPacking
->SwapBytes
&&
3798 baseInternalFormat
== srcFormat
&&
3799 srcType
== GL_UNSIGNED_SHORT
) {
3800 /* simple memcpy path */
3801 memcpy_texture(ctx
, dims
,
3802 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3805 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3806 srcAddr
, srcPacking
);
3810 const GLuint
*tempImage
=
3811 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3812 srcWidth
, srcHeight
, srcDepth
,
3813 srcFormat
, srcType
, srcAddr
, srcPacking
);
3814 const GLuint
*src
= tempImage
;
3818 for (img
= 0; img
< srcDepth
; img
++) {
3819 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3820 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3821 + dstYoffset
* dstRowStride
3822 + dstXoffset
* texelBytes
;
3823 for (row
= 0; row
< srcHeight
; row
++) {
3824 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3826 for (i
= 0; i
< srcWidth
* components
; i
++) {
3827 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3829 dstRow
+= dstRowStride
;
3830 src
+= srcWidth
* components
;
3834 free((void *) tempImage
);
3840 /* non-normalized, unsigned int32 */
3842 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3844 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3845 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3846 const GLint components
= _mesa_components_in_format(baseFormat
);
3848 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3849 ASSERT(baseInternalFormat
== GL_RGBA
||
3850 baseInternalFormat
== GL_RGB
||
3851 baseInternalFormat
== GL_ALPHA
||
3852 baseInternalFormat
== GL_LUMINANCE
||
3853 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3854 baseInternalFormat
== GL_INTENSITY
);
3855 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3857 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3858 * to integer formats.
3860 if (!srcPacking
->SwapBytes
&&
3861 baseInternalFormat
== srcFormat
&&
3862 srcType
== GL_UNSIGNED_INT
) {
3863 /* simple memcpy path */
3864 memcpy_texture(ctx
, dims
,
3865 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3868 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3869 srcAddr
, srcPacking
);
3873 const GLuint
*tempImage
=
3874 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3875 srcWidth
, srcHeight
, srcDepth
,
3876 srcFormat
, srcType
, srcAddr
, srcPacking
);
3877 const GLuint
*src
= tempImage
;
3881 for (img
= 0; img
< srcDepth
; img
++) {
3882 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3883 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3884 + dstYoffset
* dstRowStride
3885 + dstXoffset
* texelBytes
;
3886 for (row
= 0; row
< srcHeight
; row
++) {
3887 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3889 for (i
= 0; i
< srcWidth
* components
; i
++) {
3890 dstTexel
[i
] = src
[i
];
3892 dstRow
+= dstRowStride
;
3893 src
+= srcWidth
* components
;
3897 free((void *) tempImage
);
3905 #if FEATURE_EXT_texture_sRGB
3907 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3909 gl_format newDstFormat
;
3912 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3914 /* reuse normal rgb texstore code */
3915 newDstFormat
= MESA_FORMAT_RGB888
;
3917 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3918 newDstFormat
, dstAddr
,
3919 dstXoffset
, dstYoffset
, dstZoffset
,
3920 dstRowStride
, dstImageOffsets
,
3921 srcWidth
, srcHeight
, srcDepth
,
3923 srcAddr
, srcPacking
);
3929 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3931 gl_format newDstFormat
;
3934 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3936 /* reuse normal rgba texstore code */
3937 newDstFormat
= MESA_FORMAT_RGBA8888
;
3938 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3939 newDstFormat
, dstAddr
,
3940 dstXoffset
, dstYoffset
, dstZoffset
,
3941 dstRowStride
, dstImageOffsets
,
3942 srcWidth
, srcHeight
, srcDepth
,
3944 srcAddr
, srcPacking
);
3950 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3952 gl_format newDstFormat
;
3955 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3957 /* reuse normal rgba texstore code */
3958 newDstFormat
= MESA_FORMAT_ARGB8888
;
3960 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3961 newDstFormat
, dstAddr
,
3962 dstXoffset
, dstYoffset
, dstZoffset
,
3963 dstRowStride
, dstImageOffsets
,
3964 srcWidth
, srcHeight
, srcDepth
,
3966 srcAddr
, srcPacking
);
3972 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3974 gl_format newDstFormat
;
3977 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3979 newDstFormat
= MESA_FORMAT_L8
;
3981 /* _mesa_textore_a8 handles luminance8 too */
3982 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3983 newDstFormat
, dstAddr
,
3984 dstXoffset
, dstYoffset
, dstZoffset
,
3985 dstRowStride
, dstImageOffsets
,
3986 srcWidth
, srcHeight
, srcDepth
,
3988 srcAddr
, srcPacking
);
3994 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3996 gl_format newDstFormat
;
3999 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4001 /* reuse normal luminance/alpha texstore code */
4002 newDstFormat
= MESA_FORMAT_AL88
;
4004 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4005 newDstFormat
, dstAddr
,
4006 dstXoffset
, dstYoffset
, dstZoffset
,
4007 dstRowStride
, dstImageOffsets
,
4008 srcWidth
, srcHeight
, srcDepth
,
4010 srcAddr
, srcPacking
);
4016 /* these are used only in texstore_funcs[] below */
4017 #define _mesa_texstore_srgb8 NULL
4018 #define _mesa_texstore_srgba8 NULL
4019 #define _mesa_texstore_sargb8 NULL
4020 #define _mesa_texstore_sl8 NULL
4021 #define _mesa_texstore_sla8 NULL
4023 #endif /* FEATURE_EXT_texture_sRGB */
4029 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4030 * XXX this is somewhat temporary.
4032 static const struct {
4034 StoreTexImageFunc Store
;
4036 texstore_funcs
[MESA_FORMAT_COUNT
] =
4038 { MESA_FORMAT_NONE
, NULL
},
4039 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
4040 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
4041 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
4042 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
4043 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
4044 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
4045 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
4046 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
4047 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
4048 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
4049 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
4050 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
4051 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
4052 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
4053 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
4054 { MESA_FORMAT_AL44
, _mesa_texstore_unorm44
},
4055 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
4056 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
4057 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
4058 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
4059 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
4060 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
4061 { MESA_FORMAT_A16
, _mesa_texstore_unorm16
},
4062 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
4063 { MESA_FORMAT_L16
, _mesa_texstore_unorm16
},
4064 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
4065 { MESA_FORMAT_I16
, _mesa_texstore_unorm16
},
4066 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
4067 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
4068 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
4069 { MESA_FORMAT_R8
, _mesa_texstore_a8
},
4070 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
4071 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
4072 { MESA_FORMAT_R16
, _mesa_texstore_unorm16
},
4073 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
4074 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
4075 { MESA_FORMAT_ARGB2101010
, _mesa_texstore_argb2101010
},
4076 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
4077 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
4078 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
4079 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
4080 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
4081 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
4082 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
4083 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
4084 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
4085 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
4086 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
4087 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
4088 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4089 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4090 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4091 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4092 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
4093 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
4094 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4095 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4096 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4097 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4098 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
4099 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
4100 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
4101 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
4102 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4103 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4104 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
4105 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
4106 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4107 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4108 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
4109 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
4111 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
4112 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
4113 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
4114 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
4115 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
4116 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
4118 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
4120 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
4121 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
4122 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
4124 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
4125 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
4127 { MESA_FORMAT_SIGNED_R_16
, _mesa_texstore_signed_rgba_16
},
4128 { MESA_FORMAT_SIGNED_RG_16
, _mesa_texstore_signed_rgba_16
},
4129 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
4130 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
4131 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
}
4136 _mesa_texstore_null(TEXSTORE_PARAMS
)
4138 (void) ctx
; (void) dims
;
4139 (void) baseInternalFormat
;
4142 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4143 (void) dstRowStride
; (void) dstImageOffsets
;
4144 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4145 (void) srcFormat
; (void) srcType
;
4149 /* should never happen */
4150 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4156 * Return the StoreTexImageFunc pointer to store an image in the given format.
4158 static StoreTexImageFunc
4159 _mesa_get_texstore_func(gl_format format
)
4163 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4164 ASSERT(texstore_funcs
[i
].Name
== i
);
4167 ASSERT(texstore_funcs
[format
].Name
== format
);
4169 if (texstore_funcs
[format
].Store
)
4170 return texstore_funcs
[format
].Store
;
4172 return _mesa_texstore_null
;
4177 * Store user data into texture memory.
4178 * Called via glTex[Sub]Image1/2/3D()
4181 _mesa_texstore(TEXSTORE_PARAMS
)
4183 StoreTexImageFunc storeImage
;
4186 storeImage
= _mesa_get_texstore_func(dstFormat
);
4188 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4189 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4190 dstRowStride
, dstImageOffsets
,
4191 srcWidth
, srcHeight
, srcDepth
,
4192 srcFormat
, srcType
, srcAddr
, srcPacking
);
4198 * Check if an unpack PBO is active prior to fetching a texture image.
4199 * If so, do bounds checking and map the buffer into main memory.
4200 * Any errors detected will be recorded.
4201 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4204 _mesa_validate_pbo_teximage(struct gl_context
*ctx
, GLuint dimensions
,
4205 GLsizei width
, GLsizei height
, GLsizei depth
,
4206 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4207 const struct gl_pixelstore_attrib
*unpack
,
4208 const char *funcName
)
4212 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
4216 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
4217 format
, type
, pixels
)) {
4218 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4222 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4223 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
4225 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped)");
4229 return ADD_POINTERS(buf
, pixels
);
4234 * Check if an unpack PBO is active prior to fetching a compressed texture
4236 * If so, do bounds checking and map the buffer into main memory.
4237 * Any errors detected will be recorded.
4238 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4241 _mesa_validate_pbo_compressed_teximage(struct gl_context
*ctx
,
4242 GLsizei imageSize
, const GLvoid
*pixels
,
4243 const struct gl_pixelstore_attrib
*packing
,
4244 const char *funcName
)
4248 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
4249 /* not using a PBO - return pointer unchanged */
4252 if ((const GLubyte
*) pixels
+ imageSize
>
4253 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
4254 /* out of bounds read! */
4255 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4259 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4260 GL_READ_ONLY_ARB
, packing
->BufferObj
);
4262 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
4266 return ADD_POINTERS(buf
, pixels
);
4271 * This function must be called after either of the validate_pbo_*_teximage()
4272 * functions. It unmaps the PBO buffer if it was mapped earlier.
4275 _mesa_unmap_teximage_pbo(struct gl_context
*ctx
,
4276 const struct gl_pixelstore_attrib
*unpack
)
4278 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
4279 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4285 /** Return texture size in bytes */
4287 texture_size(const struct gl_texture_image
*texImage
)
4289 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4290 texImage
->Height
, texImage
->Depth
);
4295 /** Return row stride in bytes */
4297 texture_row_stride(const struct gl_texture_image
*texImage
)
4299 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4307 * This is the software fallback for Driver.TexImage1D()
4308 * and Driver.CopyTexImage1D().
4309 * \sa _mesa_store_teximage2d()
4312 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4313 GLint internalFormat
,
4314 GLint width
, GLint border
,
4315 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4316 const struct gl_pixelstore_attrib
*packing
,
4317 struct gl_texture_object
*texObj
,
4318 struct gl_texture_image
*texImage
)
4323 /* allocate memory */
4324 sizeInBytes
= texture_size(texImage
);
4325 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4326 if (!texImage
->Data
) {
4327 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4331 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4332 pixels
, packing
, "glTexImage1D");
4334 /* Note: we check for a NULL image pointer here, _after_ we allocated
4335 * memory for the texture. That's what the GL spec calls for.
4340 const GLint dstRowStride
= 0;
4341 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4342 texImage
->TexFormat
,
4344 0, 0, 0, /* dstX/Y/Zoffset */
4346 texImage
->ImageOffsets
,
4348 format
, type
, pixels
, packing
);
4350 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4354 _mesa_unmap_teximage_pbo(ctx
, packing
);
4359 * This is the software fallback for Driver.TexImage2D()
4360 * and Driver.CopyTexImage2D().
4362 * This function is oriented toward storing images in main memory, rather
4363 * than VRAM. Device driver's can easily plug in their own replacement.
4366 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4367 GLint internalFormat
,
4368 GLint width
, GLint height
, GLint border
,
4369 GLenum format
, GLenum type
, const void *pixels
,
4370 const struct gl_pixelstore_attrib
*packing
,
4371 struct gl_texture_object
*texObj
,
4372 struct gl_texture_image
*texImage
)
4377 /* allocate memory */
4378 sizeInBytes
= texture_size(texImage
);
4379 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4380 if (!texImage
->Data
) {
4381 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4385 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4386 pixels
, packing
, "glTexImage2D");
4388 /* Note: we check for a NULL image pointer here, _after_ we allocated
4389 * memory for the texture. That's what the GL spec calls for.
4394 GLint dstRowStride
= texture_row_stride(texImage
);
4395 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4396 texImage
->TexFormat
,
4398 0, 0, 0, /* dstX/Y/Zoffset */
4400 texImage
->ImageOffsets
,
4402 format
, type
, pixels
, packing
);
4404 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4408 _mesa_unmap_teximage_pbo(ctx
, packing
);
4414 * This is the software fallback for Driver.TexImage3D()
4415 * and Driver.CopyTexImage3D().
4416 * \sa _mesa_store_teximage2d()
4419 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4420 GLint internalFormat
,
4421 GLint width
, GLint height
, GLint depth
, GLint border
,
4422 GLenum format
, GLenum type
, const void *pixels
,
4423 const struct gl_pixelstore_attrib
*packing
,
4424 struct gl_texture_object
*texObj
,
4425 struct gl_texture_image
*texImage
)
4430 /* allocate memory */
4431 sizeInBytes
= texture_size(texImage
);
4432 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4433 if (!texImage
->Data
) {
4434 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4438 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4439 type
, pixels
, packing
, "glTexImage3D");
4441 /* Note: we check for a NULL image pointer here, _after_ we allocated
4442 * memory for the texture. That's what the GL spec calls for.
4447 GLint dstRowStride
= texture_row_stride(texImage
);
4448 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4449 texImage
->TexFormat
,
4451 0, 0, 0, /* dstX/Y/Zoffset */
4453 texImage
->ImageOffsets
,
4454 width
, height
, depth
,
4455 format
, type
, pixels
, packing
);
4457 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4461 _mesa_unmap_teximage_pbo(ctx
, packing
);
4468 * This is the software fallback for Driver.TexSubImage1D()
4469 * and Driver.CopyTexSubImage1D().
4472 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4473 GLint xoffset
, GLint width
,
4474 GLenum format
, GLenum type
, const void *pixels
,
4475 const struct gl_pixelstore_attrib
*packing
,
4476 struct gl_texture_object
*texObj
,
4477 struct gl_texture_image
*texImage
)
4479 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4480 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4481 pixels
, packing
, "glTexSubImage1D");
4486 const GLint dstRowStride
= 0;
4487 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4488 texImage
->TexFormat
,
4490 xoffset
, 0, 0, /* offsets */
4492 texImage
->ImageOffsets
,
4494 format
, type
, pixels
, packing
);
4496 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4500 _mesa_unmap_teximage_pbo(ctx
, packing
);
4506 * This is the software fallback for Driver.TexSubImage2D()
4507 * and Driver.CopyTexSubImage2D().
4510 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4511 GLint xoffset
, GLint yoffset
,
4512 GLint width
, GLint height
,
4513 GLenum format
, GLenum type
, const void *pixels
,
4514 const struct gl_pixelstore_attrib
*packing
,
4515 struct gl_texture_object
*texObj
,
4516 struct gl_texture_image
*texImage
)
4518 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4519 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4520 pixels
, packing
, "glTexSubImage2D");
4525 GLint dstRowStride
= texture_row_stride(texImage
);
4526 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4527 texImage
->TexFormat
,
4529 xoffset
, yoffset
, 0,
4531 texImage
->ImageOffsets
,
4533 format
, type
, pixels
, packing
);
4535 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4539 _mesa_unmap_teximage_pbo(ctx
, packing
);
4544 * This is the software fallback for Driver.TexSubImage3D().
4545 * and Driver.CopyTexSubImage3D().
4548 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4549 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4550 GLint width
, GLint height
, GLint depth
,
4551 GLenum format
, GLenum type
, const void *pixels
,
4552 const struct gl_pixelstore_attrib
*packing
,
4553 struct gl_texture_object
*texObj
,
4554 struct gl_texture_image
*texImage
)
4556 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4557 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4558 type
, pixels
, packing
,
4564 GLint dstRowStride
= texture_row_stride(texImage
);
4565 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4566 texImage
->TexFormat
,
4568 xoffset
, yoffset
, zoffset
,
4570 texImage
->ImageOffsets
,
4571 width
, height
, depth
,
4572 format
, type
, pixels
, packing
);
4574 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4578 _mesa_unmap_teximage_pbo(ctx
, packing
);
4583 * Fallback for Driver.CompressedTexImage1D()
4586 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4587 GLenum target
, GLint level
,
4588 GLint internalFormat
,
4589 GLint width
, GLint border
,
4590 GLsizei imageSize
, const GLvoid
*data
,
4591 struct gl_texture_object
*texObj
,
4592 struct gl_texture_image
*texImage
)
4594 /* this space intentionally left blank */
4596 (void) target
; (void) level
;
4597 (void) internalFormat
;
4598 (void) width
; (void) border
;
4599 (void) imageSize
; (void) data
;
4607 * Fallback for Driver.CompressedTexImage2D()
4610 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4611 GLenum target
, GLint level
,
4612 GLint internalFormat
,
4613 GLint width
, GLint height
, GLint border
,
4614 GLsizei imageSize
, const GLvoid
*data
,
4615 struct gl_texture_object
*texObj
,
4616 struct gl_texture_image
*texImage
)
4618 (void) width
; (void) height
; (void) border
;
4620 /* This is pretty simple, basically just do a memcpy without worrying
4621 * about the usual image unpacking or image transfer operations.
4625 ASSERT(texImage
->Width
> 0);
4626 ASSERT(texImage
->Height
> 0);
4627 ASSERT(texImage
->Depth
== 1);
4628 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4630 /* allocate storage */
4631 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4632 if (!texImage
->Data
) {
4633 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4637 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4639 "glCompressedTexImage2D");
4644 memcpy(texImage
->Data
, data
, imageSize
);
4646 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4652 * Fallback for Driver.CompressedTexImage3D()
4655 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4656 GLenum target
, GLint level
,
4657 GLint internalFormat
,
4658 GLint width
, GLint height
, GLint depth
,
4660 GLsizei imageSize
, const GLvoid
*data
,
4661 struct gl_texture_object
*texObj
,
4662 struct gl_texture_image
*texImage
)
4664 /* this space intentionally left blank */
4666 (void) target
; (void) level
;
4667 (void) internalFormat
;
4668 (void) width
; (void) height
; (void) depth
;
4670 (void) imageSize
; (void) data
;
4678 * Fallback for Driver.CompressedTexSubImage1D()
4681 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4683 GLint xoffset
, GLsizei width
,
4685 GLsizei imageSize
, const GLvoid
*data
,
4686 struct gl_texture_object
*texObj
,
4687 struct gl_texture_image
*texImage
)
4689 /* there are no compressed 1D texture formats yet */
4691 (void) target
; (void) level
;
4692 (void) xoffset
; (void) width
;
4694 (void) imageSize
; (void) data
;
4701 * Fallback for Driver.CompressedTexSubImage2D()
4704 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4706 GLint xoffset
, GLint yoffset
,
4707 GLsizei width
, GLsizei height
,
4709 GLsizei imageSize
, const GLvoid
*data
,
4710 struct gl_texture_object
*texObj
,
4711 struct gl_texture_image
*texImage
)
4713 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4717 const gl_format texFormat
= texImage
->TexFormat
;
4718 const GLint destWidth
= texImage
->Width
;
4721 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4726 /* these should have been caught sooner */
4727 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4728 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4729 ASSERT((xoffset
% bw
) == 0);
4730 ASSERT((yoffset
% bh
) == 0);
4732 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4733 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4735 "glCompressedTexSubImage2D");
4739 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4740 src
= (const GLubyte
*) data
;
4742 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4743 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4744 texFormat
, destWidth
,
4745 (GLubyte
*) texImage
->Data
);
4747 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4748 rows
= height
/ bh
; /* rows in blocks */
4750 /* copy rows of blocks */
4751 for (i
= 0; i
< rows
; i
++) {
4752 memcpy(dest
, src
, bytesPerRow
);
4753 dest
+= destRowStride
;
4754 src
+= srcRowStride
;
4757 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4762 * Fallback for Driver.CompressedTexSubImage3D()
4765 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4767 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4768 GLsizei width
, GLsizei height
, GLsizei depth
,
4770 GLsizei imageSize
, const GLvoid
*data
,
4771 struct gl_texture_object
*texObj
,
4772 struct gl_texture_image
*texImage
)
4774 /* there are no compressed 3D texture formats yet */
4776 (void) target
; (void) level
;
4777 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4778 (void) width
; (void) height
; (void) depth
;
4780 (void) imageSize
; (void) data
;