2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
82 * Texture image storage function.
84 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
88 * Return GL_TRUE if the given image format is one that be converted
89 * to another format by swizzling.
92 can_swizzle(GLenum logicalBaseFormat
)
94 switch (logicalBaseFormat
) {
97 case GL_LUMINANCE_ALPHA
:
133 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
134 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
135 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
136 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
139 static const struct {
142 GLubyte from_rgba
[6];
143 } mappings
[MAX_IDX
] =
153 MAP4(ZERO
, ZERO
, ZERO
, 0),
183 MAP4(0, ZERO
, ZERO
, ONE
),
189 MAP4(ZERO
, 0, ZERO
, ONE
),
195 MAP4(ZERO
, ZERO
, 0, ONE
),
219 MAP4(0, 1, ZERO
, ONE
),
227 * Convert a GL image format enum to an IDX_* value (see above).
230 get_map_idx(GLenum value
)
233 case GL_LUMINANCE
: return IDX_LUMINANCE
;
234 case GL_ALPHA
: return IDX_ALPHA
;
235 case GL_INTENSITY
: return IDX_INTENSITY
;
236 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
237 case GL_RGB
: return IDX_RGB
;
238 case GL_RGBA
: return IDX_RGBA
;
239 case GL_RED
: return IDX_RED
;
240 case GL_GREEN
: return IDX_GREEN
;
241 case GL_BLUE
: return IDX_BLUE
;
242 case GL_BGR
: return IDX_BGR
;
243 case GL_BGRA
: return IDX_BGRA
;
244 case GL_ABGR_EXT
: return IDX_ABGR
;
245 case GL_RG
: return IDX_RG
;
247 _mesa_problem(NULL
, "Unexpected inFormat");
254 * When promoting texture formats (see below) we need to compute the
255 * mapping of dest components back to source components.
256 * This function does that.
257 * \param inFormat the incoming format of the texture
258 * \param outFormat the final texture format
259 * \return map[6] a full 6-component map
262 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
265 const int inFmt
= get_map_idx(inFormat
);
266 const int outFmt
= get_map_idx(outFormat
);
267 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
268 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
271 for (i
= 0; i
< 4; i
++)
272 map
[i
] = in2rgba
[rgba2out
[i
]];
278 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
279 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
280 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
292 * Make a temporary (color) texture image with GLfloat components.
293 * Apply all needed pixel unpacking and pixel transfer operations.
294 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
295 * Suppose the user specifies GL_LUMINANCE as the internal texture format
296 * but the graphics hardware doesn't support luminance textures. So, we might
297 * use an RGB hardware format instead.
298 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
300 * \param ctx the rendering context
301 * \param dims image dimensions: 1, 2 or 3
302 * \param logicalBaseFormat basic texture derived from the user's
303 * internal texture format value
304 * \param textureBaseFormat the actual basic format of the texture
305 * \param srcWidth source image width
306 * \param srcHeight source image height
307 * \param srcDepth source image depth
308 * \param srcFormat source image format
309 * \param srcType source image type
310 * \param srcAddr source image address
311 * \param srcPacking source image pixel packing
312 * \return resulting image with format = textureBaseFormat and type = GLfloat.
315 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
316 GLenum logicalBaseFormat
,
317 GLenum textureBaseFormat
,
318 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
319 GLenum srcFormat
, GLenum srcType
,
320 const GLvoid
*srcAddr
,
321 const struct gl_pixelstore_attrib
*srcPacking
,
322 GLbitfield transferOps
)
325 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
326 const GLint srcStride
=
327 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
331 ASSERT(dims
>= 1 && dims
<= 3);
333 ASSERT(logicalBaseFormat
== GL_RGBA
||
334 logicalBaseFormat
== GL_RGB
||
335 logicalBaseFormat
== GL_RG
||
336 logicalBaseFormat
== GL_RED
||
337 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
338 logicalBaseFormat
== GL_LUMINANCE
||
339 logicalBaseFormat
== GL_ALPHA
||
340 logicalBaseFormat
== GL_INTENSITY
||
341 logicalBaseFormat
== GL_COLOR_INDEX
||
342 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
344 ASSERT(textureBaseFormat
== GL_RGBA
||
345 textureBaseFormat
== GL_RGB
||
346 textureBaseFormat
== GL_RG
||
347 textureBaseFormat
== GL_RED
||
348 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
349 textureBaseFormat
== GL_LUMINANCE
||
350 textureBaseFormat
== GL_ALPHA
||
351 textureBaseFormat
== GL_INTENSITY
||
352 textureBaseFormat
== GL_COLOR_INDEX
||
353 textureBaseFormat
== GL_DEPTH_COMPONENT
);
355 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
356 * components
* sizeof(GLfloat
));
361 for (img
= 0; img
< srcDepth
; img
++) {
363 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
367 for (row
= 0; row
< srcHeight
; row
++) {
368 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
369 dst
, srcFormat
, srcType
, src
,
370 srcPacking
, transferOps
);
371 dst
+= srcWidth
* components
;
376 if (logicalBaseFormat
!= textureBaseFormat
) {
378 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
379 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
384 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
385 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
386 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
388 /* The actual texture format should have at least as many components
389 * as the logical texture format.
391 ASSERT(texComponents
>= logComponents
);
393 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
394 * texComponents
* sizeof(GLfloat
));
400 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
402 n
= srcWidth
* srcHeight
* srcDepth
;
403 for (i
= 0; i
< n
; i
++) {
405 for (k
= 0; k
< texComponents
; k
++) {
408 newImage
[i
* texComponents
+ k
] = 0.0F
;
410 newImage
[i
* texComponents
+ k
] = 1.0F
;
412 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
417 tempImage
= newImage
;
425 * Make temporary image with uint pixel values. Used for unsigned
426 * integer-valued textures.
429 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
430 GLenum logicalBaseFormat
,
431 GLenum textureBaseFormat
,
432 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
433 GLenum srcFormat
, GLenum srcType
,
434 const GLvoid
*srcAddr
,
435 const struct gl_pixelstore_attrib
*srcPacking
)
438 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
439 const GLint srcStride
=
440 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
444 ASSERT(dims
>= 1 && dims
<= 3);
446 ASSERT(logicalBaseFormat
== GL_RGBA
||
447 logicalBaseFormat
== GL_RGB
||
448 logicalBaseFormat
== GL_RG
||
449 logicalBaseFormat
== GL_RED
||
450 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
451 logicalBaseFormat
== GL_LUMINANCE
||
452 logicalBaseFormat
== GL_INTENSITY
||
453 logicalBaseFormat
== GL_ALPHA
);
455 ASSERT(textureBaseFormat
== GL_RGBA
||
456 textureBaseFormat
== GL_RGB
||
457 textureBaseFormat
== GL_RG
||
458 textureBaseFormat
== GL_RED
||
459 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
460 textureBaseFormat
== GL_LUMINANCE
||
461 textureBaseFormat
== GL_ALPHA
);
463 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
464 * components
* sizeof(GLuint
));
469 for (img
= 0; img
< srcDepth
; img
++) {
471 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
475 for (row
= 0; row
< srcHeight
; row
++) {
476 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
477 dst
, srcFormat
, srcType
, src
,
479 dst
+= srcWidth
* components
;
484 if (logicalBaseFormat
!= textureBaseFormat
) {
486 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
487 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
492 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
493 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
494 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
496 /* The actual texture format should have at least as many components
497 * as the logical texture format.
499 ASSERT(texComponents
>= logComponents
);
501 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
502 * texComponents
* sizeof(GLuint
));
508 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
510 n
= srcWidth
* srcHeight
* srcDepth
;
511 for (i
= 0; i
< n
; i
++) {
513 for (k
= 0; k
< texComponents
; k
++) {
516 newImage
[i
* texComponents
+ k
] = 0.0F
;
518 newImage
[i
* texComponents
+ k
] = 1.0F
;
520 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
525 tempImage
= newImage
;
534 * Make a temporary (color) texture image with GLchan components.
535 * Apply all needed pixel unpacking and pixel transfer operations.
536 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
537 * Suppose the user specifies GL_LUMINANCE as the internal texture format
538 * but the graphics hardware doesn't support luminance textures. So, we might
539 * use an RGB hardware format instead.
540 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
542 * \param ctx the rendering context
543 * \param dims image dimensions: 1, 2 or 3
544 * \param logicalBaseFormat basic texture derived from the user's
545 * internal texture format value
546 * \param textureBaseFormat the actual basic format of the texture
547 * \param srcWidth source image width
548 * \param srcHeight source image height
549 * \param srcDepth source image depth
550 * \param srcFormat source image format
551 * \param srcType source image type
552 * \param srcAddr source image address
553 * \param srcPacking source image pixel packing
554 * \return resulting image with format = textureBaseFormat and type = GLchan.
557 _mesa_make_temp_chan_image(struct gl_context
*ctx
, GLuint dims
,
558 GLenum logicalBaseFormat
,
559 GLenum textureBaseFormat
,
560 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
561 GLenum srcFormat
, GLenum srcType
,
562 const GLvoid
*srcAddr
,
563 const struct gl_pixelstore_attrib
*srcPacking
)
565 GLuint transferOps
= ctx
->_ImageTransferState
;
566 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
568 GLchan
*tempImage
, *dst
;
570 ASSERT(dims
>= 1 && dims
<= 3);
572 ASSERT(logicalBaseFormat
== GL_RGBA
||
573 logicalBaseFormat
== GL_RGB
||
574 logicalBaseFormat
== GL_RG
||
575 logicalBaseFormat
== GL_RED
||
576 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
577 logicalBaseFormat
== GL_LUMINANCE
||
578 logicalBaseFormat
== GL_ALPHA
||
579 logicalBaseFormat
== GL_INTENSITY
);
581 ASSERT(textureBaseFormat
== GL_RGBA
||
582 textureBaseFormat
== GL_RGB
||
583 textureBaseFormat
== GL_RG
||
584 textureBaseFormat
== GL_RED
||
585 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
586 textureBaseFormat
== GL_LUMINANCE
||
587 textureBaseFormat
== GL_ALPHA
||
588 textureBaseFormat
== GL_INTENSITY
);
590 /* unpack and transfer the source image */
591 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
592 * components
* sizeof(GLchan
));
598 for (img
= 0; img
< srcDepth
; img
++) {
599 const GLint srcStride
=
600 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
602 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
606 for (row
= 0; row
< srcHeight
; row
++) {
607 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
608 srcFormat
, srcType
, src
, srcPacking
,
610 dst
+= srcWidth
* components
;
615 if (logicalBaseFormat
!= textureBaseFormat
) {
616 /* one more conversion step */
617 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
618 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
623 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
624 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
625 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
627 /* The actual texture format should have at least as many components
628 * as the logical texture format.
630 ASSERT(texComponents
>= logComponents
);
632 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
633 * texComponents
* sizeof(GLchan
));
639 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
641 n
= srcWidth
* srcHeight
* srcDepth
;
642 for (i
= 0; i
< n
; i
++) {
644 for (k
= 0; k
< texComponents
; k
++) {
647 newImage
[i
* texComponents
+ k
] = 0;
649 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
651 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
656 tempImage
= newImage
;
664 * Copy GLubyte pixels from <src> to <dst> with swizzling.
665 * \param dst destination pixels
666 * \param dstComponents number of color components in destination pixels
667 * \param src source pixels
668 * \param srcComponents number of color components in source pixels
669 * \param map the swizzle mapping. map[X] says where to find the X component
670 * in the source image's pixels. For example, if the source image
671 * is GL_BGRA and X = red, map[0] yields 2.
672 * \param count number of pixels to copy/swizzle.
675 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
676 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
678 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
681 for (i = 0; i < count; i++) { \
683 if (srcComps == 4) { \
684 COPY_4UBV(tmp, src); \
687 for (j = 0; j < srcComps; j++) { \
692 for (j = 0; j < dstComps; j++) { \
693 dst[j] = tmp[map[j]]; \
704 ASSERT(srcComponents
<= 4);
705 ASSERT(dstComponents
<= 4);
707 switch (dstComponents
) {
709 switch (srcComponents
) {
711 SWZ_CPY(dst
, src
, count
, 4, 4);
714 SWZ_CPY(dst
, src
, count
, 4, 3);
717 SWZ_CPY(dst
, src
, count
, 4, 2);
720 SWZ_CPY(dst
, src
, count
, 4, 1);
727 switch (srcComponents
) {
729 SWZ_CPY(dst
, src
, count
, 3, 4);
732 SWZ_CPY(dst
, src
, count
, 3, 3);
735 SWZ_CPY(dst
, src
, count
, 3, 2);
738 SWZ_CPY(dst
, src
, count
, 3, 1);
745 switch (srcComponents
) {
747 SWZ_CPY(dst
, src
, count
, 2, 4);
750 SWZ_CPY(dst
, src
, count
, 2, 3);
753 SWZ_CPY(dst
, src
, count
, 2, 2);
756 SWZ_CPY(dst
, src
, count
, 2, 1);
763 switch (srcComponents
) {
765 SWZ_CPY(dst
, src
, count
, 1, 4);
768 SWZ_CPY(dst
, src
, count
, 1, 3);
771 SWZ_CPY(dst
, src
, count
, 1, 2);
774 SWZ_CPY(dst
, src
, count
, 1, 1);
788 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
789 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
793 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
794 * mapping array depending on endianness.
796 static const GLubyte
*
797 type_mapping( GLenum srcType
)
801 case GL_UNSIGNED_BYTE
:
803 case GL_UNSIGNED_INT_8_8_8_8
:
804 return _mesa_little_endian() ? map_3210
: map_identity
;
805 case GL_UNSIGNED_INT_8_8_8_8_REV
:
806 return _mesa_little_endian() ? map_identity
: map_3210
;
814 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
815 * mapping array depending on pixelstore byte swapping state.
817 static const GLubyte
*
818 byteswap_mapping( GLboolean swapBytes
,
826 case GL_UNSIGNED_BYTE
:
828 case GL_UNSIGNED_INT_8_8_8_8
:
829 case GL_UNSIGNED_INT_8_8_8_8_REV
:
839 * Transfer a GLubyte texture image with component swizzling.
842 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
847 GLenum baseInternalFormat
,
849 const GLubyte
*rgba2dst
,
850 GLuint dstComponents
,
853 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
855 const GLuint
*dstImageOffsets
,
857 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
858 const GLvoid
*srcAddr
,
859 const struct gl_pixelstore_attrib
*srcPacking
)
861 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
862 const GLubyte
*srctype2ubyte
, *swap
;
863 GLubyte map
[4], src2base
[6], base2rgba
[6];
865 const GLint srcRowStride
=
866 _mesa_image_row_stride(srcPacking
, srcWidth
,
867 srcFormat
, GL_UNSIGNED_BYTE
);
868 const GLint srcImageStride
869 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
871 const GLubyte
*srcImage
872 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
873 srcWidth
, srcHeight
, srcFormat
,
874 GL_UNSIGNED_BYTE
, 0, 0, 0);
878 /* Translate from src->baseInternal->GL_RGBA->dst. This will
879 * correctly deal with RGBA->RGB->RGBA conversions where the final
880 * A value must be 0xff regardless of the incoming alpha values.
882 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
883 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
884 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
885 srctype2ubyte
= type_mapping(srcType
);
888 for (i
= 0; i
< 4; i
++)
889 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
891 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
893 if (srcComponents
== dstComponents
&&
894 srcRowStride
== dstRowStride
&&
895 srcRowStride
== srcWidth
* srcComponents
&&
897 /* 1 and 2D images only */
898 GLubyte
*dstImage
= (GLubyte
*) dstAddr
899 + dstYoffset
* dstRowStride
900 + dstXoffset
* dstComponents
;
901 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
902 srcWidth
* srcHeight
);
906 for (img
= 0; img
< srcDepth
; img
++) {
907 const GLubyte
*srcRow
= srcImage
;
908 GLubyte
*dstRow
= (GLubyte
*) dstAddr
909 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
910 + dstYoffset
* dstRowStride
911 + dstXoffset
* dstComponents
;
912 for (row
= 0; row
< srcHeight
; row
++) {
913 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
914 dstRow
+= dstRowStride
;
915 srcRow
+= srcRowStride
;
917 srcImage
+= srcImageStride
;
924 * Teximage storage routine for when a simple memcpy will do.
925 * No pixel transfer operations or special texel encodings allowed.
926 * 1D, 2D and 3D images supported.
929 memcpy_texture(struct gl_context
*ctx
,
933 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
935 const GLuint
*dstImageOffsets
,
936 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
937 GLenum srcFormat
, GLenum srcType
,
938 const GLvoid
*srcAddr
,
939 const struct gl_pixelstore_attrib
*srcPacking
)
941 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
943 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
944 srcWidth
, srcHeight
, srcFormat
, srcType
);
945 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
946 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
947 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
948 const GLint bytesPerRow
= srcWidth
* texelBytes
;
951 /* XXX update/re-enable for dstImageOffsets array */
952 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
953 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
954 GLubyte
*dstImage
= (GLubyte
*) dstAddr
955 + dstZoffset
* dstImageStride
956 + dstYoffset
* dstRowStride
957 + dstXoffset
* texelBytes
;
959 if (dstRowStride
== srcRowStride
&&
960 dstRowStride
== bytesPerRow
&&
961 ((dstImageStride
== srcImageStride
&&
962 dstImageStride
== bytesPerImage
) ||
965 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
970 for (img
= 0; img
< srcDepth
; img
++) {
971 const GLubyte
*srcRow
= srcImage
;
972 GLubyte
*dstRow
= dstImage
;
973 for (row
= 0; row
< srcHeight
; row
++) {
974 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
975 dstRow
+= dstRowStride
;
976 srcRow
+= srcRowStride
;
978 srcImage
+= srcImageStride
;
979 dstImage
+= dstImageStride
;
985 for (img
= 0; img
< srcDepth
; img
++) {
986 const GLubyte
*srcRow
= srcImage
;
987 GLubyte
*dstRow
= (GLubyte
*) dstAddr
988 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
989 + dstYoffset
* dstRowStride
990 + dstXoffset
* texelBytes
;
991 for (row
= 0; row
< srcHeight
; row
++) {
992 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
993 dstRow
+= dstRowStride
;
994 srcRow
+= srcRowStride
;
996 srcImage
+= srcImageStride
;
1003 * Store a 32-bit integer depth component texture image.
1006 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1008 const GLuint depthScale
= 0xffffffff;
1009 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1011 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1012 ASSERT(texelBytes
== sizeof(GLuint
));
1014 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1015 ctx
->Pixel
.DepthBias
== 0.0f
&&
1016 !srcPacking
->SwapBytes
&&
1017 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1018 srcFormat
== GL_DEPTH_COMPONENT
&&
1019 srcType
== GL_UNSIGNED_INT
) {
1020 /* simple memcpy path */
1021 memcpy_texture(ctx
, dims
,
1022 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1025 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1026 srcAddr
, srcPacking
);
1031 for (img
= 0; img
< srcDepth
; img
++) {
1032 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1033 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1034 + dstYoffset
* dstRowStride
1035 + dstXoffset
* texelBytes
;
1036 for (row
= 0; row
< srcHeight
; row
++) {
1037 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1038 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1039 _mesa_unpack_depth_span(ctx
, srcWidth
,
1040 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1041 depthScale
, srcType
, src
, srcPacking
);
1042 dstRow
+= dstRowStride
;
1051 * Store a 24-bit integer depth component texture image.
1054 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1056 const GLuint depthScale
= 0xffffff;
1057 const GLuint texelBytes
= 4;
1060 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1065 for (img
= 0; img
< srcDepth
; img
++) {
1066 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1067 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1068 + dstYoffset
* dstRowStride
1069 + dstXoffset
* texelBytes
;
1070 for (row
= 0; row
< srcHeight
; row
++) {
1071 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1072 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1073 _mesa_unpack_depth_span(ctx
, srcWidth
,
1074 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1075 depthScale
, srcType
, src
, srcPacking
);
1076 dstRow
+= dstRowStride
;
1085 * Store a 24-bit integer depth component texture image.
1088 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1090 const GLuint depthScale
= 0xffffff;
1091 const GLuint texelBytes
= 4;
1094 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1099 for (img
= 0; img
< srcDepth
; img
++) {
1100 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1101 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1102 + dstYoffset
* dstRowStride
1103 + dstXoffset
* texelBytes
;
1104 for (row
= 0; row
< srcHeight
; row
++) {
1105 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1106 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1107 GLuint
*dst
= (GLuint
*) dstRow
;
1109 _mesa_unpack_depth_span(ctx
, srcWidth
,
1110 GL_UNSIGNED_INT
, dst
,
1111 depthScale
, srcType
, src
, srcPacking
);
1112 for (i
= 0; i
< srcWidth
; i
++)
1114 dstRow
+= dstRowStride
;
1123 * Store a 16-bit integer depth component texture image.
1126 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1128 const GLuint depthScale
= 0xffff;
1129 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1131 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1132 ASSERT(texelBytes
== sizeof(GLushort
));
1134 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1135 ctx
->Pixel
.DepthBias
== 0.0f
&&
1136 !srcPacking
->SwapBytes
&&
1137 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1138 srcFormat
== GL_DEPTH_COMPONENT
&&
1139 srcType
== GL_UNSIGNED_SHORT
) {
1140 /* simple memcpy path */
1141 memcpy_texture(ctx
, dims
,
1142 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1145 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1146 srcAddr
, srcPacking
);
1151 for (img
= 0; img
< srcDepth
; img
++) {
1152 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1153 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1154 + dstYoffset
* dstRowStride
1155 + dstXoffset
* texelBytes
;
1156 for (row
= 0; row
< srcHeight
; row
++) {
1157 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1158 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1159 GLushort
*dst16
= (GLushort
*) dstRow
;
1160 _mesa_unpack_depth_span(ctx
, srcWidth
,
1161 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1162 srcType
, src
, srcPacking
);
1163 dstRow
+= dstRowStride
;
1172 * Store an rgb565 or rgb565_rev texture image.
1175 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1177 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1178 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1180 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1181 dstFormat
== MESA_FORMAT_RGB565_REV
);
1182 ASSERT(texelBytes
== 2);
1184 if (!ctx
->_ImageTransferState
&&
1185 !srcPacking
->SwapBytes
&&
1186 dstFormat
== MESA_FORMAT_RGB565
&&
1187 baseInternalFormat
== GL_RGB
&&
1188 srcFormat
== GL_RGB
&&
1189 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1190 /* simple memcpy path */
1191 memcpy_texture(ctx
, dims
,
1192 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1195 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1196 srcAddr
, srcPacking
);
1198 else if (!ctx
->_ImageTransferState
&&
1199 !srcPacking
->SwapBytes
&&
1200 baseInternalFormat
== GL_RGB
&&
1201 srcFormat
== GL_RGB
&&
1202 srcType
== GL_UNSIGNED_BYTE
&&
1204 /* do optimized tex store */
1205 const GLint srcRowStride
=
1206 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1207 const GLubyte
*src
= (const GLubyte
*)
1208 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1209 srcFormat
, srcType
, 0, 0, 0);
1210 GLubyte
*dst
= (GLubyte
*) dstAddr
1211 + dstYoffset
* dstRowStride
1212 + dstXoffset
* texelBytes
;
1214 for (row
= 0; row
< srcHeight
; row
++) {
1215 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1216 GLushort
*dstUS
= (GLushort
*) dst
;
1217 /* check for byteswapped format */
1218 if (dstFormat
== MESA_FORMAT_RGB565
) {
1219 for (col
= 0; col
< srcWidth
; col
++) {
1220 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1225 for (col
= 0; col
< srcWidth
; col
++) {
1226 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1230 dst
+= dstRowStride
;
1231 src
+= srcRowStride
;
1236 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1239 srcWidth
, srcHeight
, srcDepth
,
1240 srcFormat
, srcType
, srcAddr
,
1242 const GLchan
*src
= tempImage
;
1243 GLint img
, row
, col
;
1246 for (img
= 0; img
< srcDepth
; img
++) {
1247 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1248 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1249 + dstYoffset
* dstRowStride
1250 + dstXoffset
* texelBytes
;
1251 for (row
= 0; row
< srcHeight
; row
++) {
1252 GLushort
*dstUS
= (GLushort
*) dstRow
;
1253 /* check for byteswapped format */
1254 if (dstFormat
== MESA_FORMAT_RGB565
) {
1255 for (col
= 0; col
< srcWidth
; col
++) {
1256 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1257 CHAN_TO_UBYTE(src
[GCOMP
]),
1258 CHAN_TO_UBYTE(src
[BCOMP
]) );
1263 for (col
= 0; col
< srcWidth
; col
++) {
1264 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1265 CHAN_TO_UBYTE(src
[GCOMP
]),
1266 CHAN_TO_UBYTE(src
[BCOMP
]) );
1270 dstRow
+= dstRowStride
;
1273 free((void *) tempImage
);
1280 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1283 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1285 const GLboolean littleEndian
= _mesa_little_endian();
1286 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1287 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1289 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1290 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1291 ASSERT(texelBytes
== 4);
1293 if (!ctx
->_ImageTransferState
&&
1294 !srcPacking
->SwapBytes
&&
1295 dstFormat
== MESA_FORMAT_RGBA8888
&&
1296 baseInternalFormat
== GL_RGBA
&&
1297 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1298 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1299 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1300 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1301 /* simple memcpy path */
1302 memcpy_texture(ctx
, dims
,
1303 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1306 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1307 srcAddr
, srcPacking
);
1309 else if (!ctx
->_ImageTransferState
&&
1310 !srcPacking
->SwapBytes
&&
1311 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1312 baseInternalFormat
== GL_RGBA
&&
1313 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1314 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1315 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1316 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1317 /* simple memcpy path */
1318 memcpy_texture(ctx
, dims
,
1319 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1322 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1323 srcAddr
, srcPacking
);
1325 else if (!ctx
->_ImageTransferState
&&
1326 (srcType
== GL_UNSIGNED_BYTE
||
1327 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1328 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1329 can_swizzle(baseInternalFormat
) &&
1330 can_swizzle(srcFormat
)) {
1334 /* dstmap - how to swizzle from RGBA to dst format:
1336 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1337 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1350 _mesa_swizzle_ubyte_image(ctx
, dims
,
1355 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1356 dstRowStride
, dstImageOffsets
,
1357 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1362 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1365 srcWidth
, srcHeight
, srcDepth
,
1366 srcFormat
, srcType
, srcAddr
,
1368 const GLchan
*src
= tempImage
;
1369 GLint img
, row
, col
;
1372 for (img
= 0; img
< srcDepth
; img
++) {
1373 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1374 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1375 + dstYoffset
* dstRowStride
1376 + dstXoffset
* texelBytes
;
1377 for (row
= 0; row
< srcHeight
; row
++) {
1378 GLuint
*dstUI
= (GLuint
*) dstRow
;
1379 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1380 for (col
= 0; col
< srcWidth
; col
++) {
1381 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1382 CHAN_TO_UBYTE(src
[GCOMP
]),
1383 CHAN_TO_UBYTE(src
[BCOMP
]),
1384 CHAN_TO_UBYTE(src
[ACOMP
]) );
1389 for (col
= 0; col
< srcWidth
; col
++) {
1390 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1391 CHAN_TO_UBYTE(src
[GCOMP
]),
1392 CHAN_TO_UBYTE(src
[BCOMP
]),
1393 CHAN_TO_UBYTE(src
[ACOMP
]) );
1397 dstRow
+= dstRowStride
;
1400 free((void *) tempImage
);
1407 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1409 const GLboolean littleEndian
= _mesa_little_endian();
1410 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1411 const GLenum baseFormat
= GL_RGBA
;
1413 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1414 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1415 dstFormat
== MESA_FORMAT_XRGB8888
||
1416 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1417 ASSERT(texelBytes
== 4);
1419 if (!ctx
->_ImageTransferState
&&
1420 !srcPacking
->SwapBytes
&&
1421 (dstFormat
== MESA_FORMAT_ARGB8888
||
1422 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1423 baseInternalFormat
== GL_RGBA
&&
1424 srcFormat
== GL_BGRA
&&
1425 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1426 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1427 /* simple memcpy path (little endian) */
1428 memcpy_texture(ctx
, dims
,
1429 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1432 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1433 srcAddr
, srcPacking
);
1435 else if (!ctx
->_ImageTransferState
&&
1436 !srcPacking
->SwapBytes
&&
1437 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1438 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1439 baseInternalFormat
== GL_RGBA
&&
1440 srcFormat
== GL_BGRA
&&
1441 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1442 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1443 /* simple memcpy path (big endian) */
1444 memcpy_texture(ctx
, dims
,
1445 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1448 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1449 srcAddr
, srcPacking
);
1451 else if (!ctx
->_ImageTransferState
&&
1452 !srcPacking
->SwapBytes
&&
1453 (dstFormat
== MESA_FORMAT_ARGB8888
||
1454 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1455 srcFormat
== GL_RGB
&&
1456 (baseInternalFormat
== GL_RGBA
||
1457 baseInternalFormat
== GL_RGB
) &&
1458 srcType
== GL_UNSIGNED_BYTE
) {
1460 for (img
= 0; img
< srcDepth
; img
++) {
1461 const GLint srcRowStride
=
1462 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1463 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1464 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1465 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1466 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1467 + dstYoffset
* dstRowStride
1468 + dstXoffset
* texelBytes
;
1469 for (row
= 0; row
< srcHeight
; row
++) {
1470 GLuint
*d4
= (GLuint
*) dstRow
;
1471 for (col
= 0; col
< srcWidth
; col
++) {
1472 d4
[col
] = PACK_COLOR_8888(0xff,
1473 srcRow
[col
* 3 + RCOMP
],
1474 srcRow
[col
* 3 + GCOMP
],
1475 srcRow
[col
* 3 + BCOMP
]);
1477 dstRow
+= dstRowStride
;
1478 srcRow
+= srcRowStride
;
1482 else if (!ctx
->_ImageTransferState
&&
1483 !srcPacking
->SwapBytes
&&
1484 dstFormat
== MESA_FORMAT_ARGB8888
&&
1485 srcFormat
== GL_RGBA
&&
1486 baseInternalFormat
== GL_RGBA
&&
1487 srcType
== GL_UNSIGNED_BYTE
) {
1488 /* same as above case, but src data has alpha too */
1489 GLint img
, row
, col
;
1490 /* For some reason, streaming copies to write-combined regions
1491 * are extremely sensitive to the characteristics of how the
1492 * source data is retrieved. By reordering the source reads to
1493 * be in-order, the speed of this operation increases by half.
1494 * Strangely the same isn't required for the RGB path, above.
1496 for (img
= 0; img
< srcDepth
; img
++) {
1497 const GLint srcRowStride
=
1498 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1499 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1500 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1501 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1502 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1503 + dstYoffset
* dstRowStride
1504 + dstXoffset
* texelBytes
;
1505 for (row
= 0; row
< srcHeight
; row
++) {
1506 GLuint
*d4
= (GLuint
*) dstRow
;
1507 for (col
= 0; col
< srcWidth
; col
++) {
1508 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1509 srcRow
[col
* 4 + RCOMP
],
1510 srcRow
[col
* 4 + GCOMP
],
1511 srcRow
[col
* 4 + BCOMP
]);
1513 dstRow
+= dstRowStride
;
1514 srcRow
+= srcRowStride
;
1518 else if (!ctx
->_ImageTransferState
&&
1519 (srcType
== GL_UNSIGNED_BYTE
||
1520 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1521 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1522 can_swizzle(baseInternalFormat
) &&
1523 can_swizzle(srcFormat
)) {
1527 /* dstmap - how to swizzle from RGBA to dst format:
1529 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1530 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1531 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1532 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1533 dstmap
[3] = 3; /* alpha */
1534 dstmap
[2] = 0; /* red */
1535 dstmap
[1] = 1; /* green */
1536 dstmap
[0] = 2; /* blue */
1539 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1540 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1541 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1542 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1549 _mesa_swizzle_ubyte_image(ctx
, dims
,
1554 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1557 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1562 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1565 srcWidth
, srcHeight
, srcDepth
,
1566 srcFormat
, srcType
, srcAddr
,
1568 const GLchan
*src
= tempImage
;
1569 GLint img
, row
, col
;
1572 for (img
= 0; img
< srcDepth
; img
++) {
1573 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1574 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1575 + dstYoffset
* dstRowStride
1576 + dstXoffset
* texelBytes
;
1577 for (row
= 0; row
< srcHeight
; row
++) {
1578 GLuint
*dstUI
= (GLuint
*) dstRow
;
1579 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1580 for (col
= 0; col
< srcWidth
; col
++) {
1581 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1582 CHAN_TO_UBYTE(src
[RCOMP
]),
1583 CHAN_TO_UBYTE(src
[GCOMP
]),
1584 CHAN_TO_UBYTE(src
[BCOMP
]) );
1588 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1589 for (col
= 0; col
< srcWidth
; col
++) {
1590 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1591 CHAN_TO_UBYTE(src
[RCOMP
]),
1592 CHAN_TO_UBYTE(src
[GCOMP
]),
1593 CHAN_TO_UBYTE(src
[BCOMP
]) );
1598 for (col
= 0; col
< srcWidth
; col
++) {
1599 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1600 CHAN_TO_UBYTE(src
[RCOMP
]),
1601 CHAN_TO_UBYTE(src
[GCOMP
]),
1602 CHAN_TO_UBYTE(src
[BCOMP
]) );
1606 dstRow
+= dstRowStride
;
1609 free((void *) tempImage
);
1616 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1618 const GLboolean littleEndian
= _mesa_little_endian();
1619 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1620 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1622 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1623 ASSERT(texelBytes
== 3);
1625 if (!ctx
->_ImageTransferState
&&
1626 !srcPacking
->SwapBytes
&&
1627 baseInternalFormat
== GL_RGB
&&
1628 srcFormat
== GL_BGR
&&
1629 srcType
== GL_UNSIGNED_BYTE
&&
1631 /* simple memcpy path */
1632 memcpy_texture(ctx
, dims
,
1633 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1636 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1637 srcAddr
, srcPacking
);
1639 else if (!ctx
->_ImageTransferState
&&
1640 !srcPacking
->SwapBytes
&&
1641 srcFormat
== GL_RGBA
&&
1642 srcType
== GL_UNSIGNED_BYTE
) {
1643 /* extract RGB from RGBA */
1644 GLint img
, row
, col
;
1645 for (img
= 0; img
< srcDepth
; img
++) {
1646 const GLint srcRowStride
=
1647 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1648 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1649 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1650 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1651 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1652 + dstYoffset
* dstRowStride
1653 + dstXoffset
* texelBytes
;
1654 for (row
= 0; row
< srcHeight
; row
++) {
1655 for (col
= 0; col
< srcWidth
; col
++) {
1656 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1657 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1658 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1660 dstRow
+= dstRowStride
;
1661 srcRow
+= srcRowStride
;
1665 else if (!ctx
->_ImageTransferState
&&
1666 srcType
== GL_UNSIGNED_BYTE
&&
1667 can_swizzle(baseInternalFormat
) &&
1668 can_swizzle(srcFormat
)) {
1672 /* dstmap - how to swizzle from RGBA to dst format:
1677 dstmap
[3] = ONE
; /* ? */
1679 _mesa_swizzle_ubyte_image(ctx
, dims
,
1684 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1685 dstRowStride
, dstImageOffsets
,
1686 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1691 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1694 srcWidth
, srcHeight
, srcDepth
,
1695 srcFormat
, srcType
, srcAddr
,
1697 const GLchan
*src
= (const GLchan
*) tempImage
;
1698 GLint img
, row
, col
;
1701 for (img
= 0; img
< srcDepth
; img
++) {
1702 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1703 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1704 + dstYoffset
* dstRowStride
1705 + dstXoffset
* texelBytes
;
1706 for (row
= 0; row
< srcHeight
; row
++) {
1709 for (col
= 0; col
< srcWidth
; col
++) {
1710 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1711 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1712 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1717 for (col
= 0; col
< srcWidth
; col
++) {
1718 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1719 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1720 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1725 for (col
= 0; col
< srcWidth
; col
++) {
1726 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1727 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1728 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1732 dstRow
+= dstRowStride
;
1735 free((void *) tempImage
);
1742 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1744 const GLboolean littleEndian
= _mesa_little_endian();
1745 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1746 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1748 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1749 ASSERT(texelBytes
== 3);
1751 if (!ctx
->_ImageTransferState
&&
1752 !srcPacking
->SwapBytes
&&
1753 baseInternalFormat
== GL_RGB
&&
1754 srcFormat
== GL_RGB
&&
1755 srcType
== GL_UNSIGNED_BYTE
&&
1757 /* simple memcpy path */
1758 memcpy_texture(ctx
, dims
,
1759 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1762 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1763 srcAddr
, srcPacking
);
1765 else if (!ctx
->_ImageTransferState
&&
1766 !srcPacking
->SwapBytes
&&
1767 srcFormat
== GL_RGBA
&&
1768 srcType
== GL_UNSIGNED_BYTE
) {
1769 /* extract BGR from RGBA */
1771 for (img
= 0; img
< srcDepth
; img
++) {
1772 const GLint srcRowStride
=
1773 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1774 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1775 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1776 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1777 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1778 + dstYoffset
* dstRowStride
1779 + dstXoffset
* texelBytes
;
1780 for (row
= 0; row
< srcHeight
; row
++) {
1781 for (col
= 0; col
< srcWidth
; col
++) {
1782 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1783 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1784 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1786 dstRow
+= dstRowStride
;
1787 srcRow
+= srcRowStride
;
1791 else if (!ctx
->_ImageTransferState
&&
1792 srcType
== GL_UNSIGNED_BYTE
&&
1793 can_swizzle(baseInternalFormat
) &&
1794 can_swizzle(srcFormat
)) {
1798 /* dstmap - how to swizzle from RGBA to dst format:
1803 dstmap
[3] = ONE
; /* ? */
1805 _mesa_swizzle_ubyte_image(ctx
, dims
,
1810 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1811 dstRowStride
, dstImageOffsets
,
1812 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1817 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1820 srcWidth
, srcHeight
, srcDepth
,
1821 srcFormat
, srcType
, srcAddr
,
1823 const GLchan
*src
= (const GLchan
*) tempImage
;
1824 GLint img
, row
, col
;
1827 for (img
= 0; img
< srcDepth
; img
++) {
1828 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1829 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1830 + dstYoffset
* dstRowStride
1831 + dstXoffset
* texelBytes
;
1832 for (row
= 0; row
< srcHeight
; row
++) {
1833 for (col
= 0; col
< srcWidth
; col
++) {
1834 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1835 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1836 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1839 dstRow
+= dstRowStride
;
1842 free((void *) tempImage
);
1849 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1851 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1852 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1854 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1855 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1856 ASSERT(texelBytes
== 2);
1858 if (!ctx
->_ImageTransferState
&&
1859 !srcPacking
->SwapBytes
&&
1860 dstFormat
== MESA_FORMAT_ARGB4444
&&
1861 baseInternalFormat
== GL_RGBA
&&
1862 srcFormat
== GL_BGRA
&&
1863 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1864 /* simple memcpy path */
1865 memcpy_texture(ctx
, dims
,
1866 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1869 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1870 srcAddr
, srcPacking
);
1874 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1877 srcWidth
, srcHeight
, srcDepth
,
1878 srcFormat
, srcType
, srcAddr
,
1880 const GLchan
*src
= tempImage
;
1881 GLint img
, row
, col
;
1884 for (img
= 0; img
< srcDepth
; img
++) {
1885 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1886 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1887 + dstYoffset
* dstRowStride
1888 + dstXoffset
* texelBytes
;
1889 for (row
= 0; row
< srcHeight
; row
++) {
1890 GLushort
*dstUS
= (GLushort
*) dstRow
;
1891 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1892 for (col
= 0; col
< srcWidth
; col
++) {
1893 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1894 CHAN_TO_UBYTE(src
[RCOMP
]),
1895 CHAN_TO_UBYTE(src
[GCOMP
]),
1896 CHAN_TO_UBYTE(src
[BCOMP
]) );
1901 for (col
= 0; col
< srcWidth
; col
++) {
1902 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1903 CHAN_TO_UBYTE(src
[RCOMP
]),
1904 CHAN_TO_UBYTE(src
[GCOMP
]),
1905 CHAN_TO_UBYTE(src
[BCOMP
]) );
1909 dstRow
+= dstRowStride
;
1912 free((void *) tempImage
);
1918 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1920 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1921 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1923 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1924 ASSERT(texelBytes
== 2);
1926 if (!ctx
->_ImageTransferState
&&
1927 !srcPacking
->SwapBytes
&&
1928 dstFormat
== MESA_FORMAT_RGBA5551
&&
1929 baseInternalFormat
== GL_RGBA
&&
1930 srcFormat
== GL_RGBA
&&
1931 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1932 /* simple memcpy path */
1933 memcpy_texture(ctx
, dims
,
1934 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1937 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1938 srcAddr
, srcPacking
);
1942 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1945 srcWidth
, srcHeight
, srcDepth
,
1946 srcFormat
, srcType
, srcAddr
,
1948 const GLchan
*src
=tempImage
;
1949 GLint img
, row
, col
;
1952 for (img
= 0; img
< srcDepth
; img
++) {
1953 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1954 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1955 + dstYoffset
* dstRowStride
1956 + dstXoffset
* texelBytes
;
1957 for (row
= 0; row
< srcHeight
; row
++) {
1958 GLushort
*dstUS
= (GLushort
*) dstRow
;
1959 for (col
= 0; col
< srcWidth
; col
++) {
1960 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1961 CHAN_TO_UBYTE(src
[GCOMP
]),
1962 CHAN_TO_UBYTE(src
[BCOMP
]),
1963 CHAN_TO_UBYTE(src
[ACOMP
]) );
1966 dstRow
+= dstRowStride
;
1969 free((void *) tempImage
);
1975 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1977 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1978 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1980 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1981 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1982 ASSERT(texelBytes
== 2);
1984 if (!ctx
->_ImageTransferState
&&
1985 !srcPacking
->SwapBytes
&&
1986 dstFormat
== MESA_FORMAT_ARGB1555
&&
1987 baseInternalFormat
== GL_RGBA
&&
1988 srcFormat
== GL_BGRA
&&
1989 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1990 /* simple memcpy path */
1991 memcpy_texture(ctx
, dims
,
1992 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1995 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1996 srcAddr
, srcPacking
);
2000 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2003 srcWidth
, srcHeight
, srcDepth
,
2004 srcFormat
, srcType
, srcAddr
,
2006 const GLchan
*src
=tempImage
;
2007 GLint img
, row
, col
;
2010 for (img
= 0; img
< srcDepth
; img
++) {
2011 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2012 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2013 + dstYoffset
* dstRowStride
2014 + dstXoffset
* texelBytes
;
2015 for (row
= 0; row
< srcHeight
; row
++) {
2016 GLushort
*dstUS
= (GLushort
*) dstRow
;
2017 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2018 for (col
= 0; col
< srcWidth
; col
++) {
2019 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
2020 CHAN_TO_UBYTE(src
[RCOMP
]),
2021 CHAN_TO_UBYTE(src
[GCOMP
]),
2022 CHAN_TO_UBYTE(src
[BCOMP
]) );
2027 for (col
= 0; col
< srcWidth
; col
++) {
2028 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2029 CHAN_TO_UBYTE(src
[RCOMP
]),
2030 CHAN_TO_UBYTE(src
[GCOMP
]),
2031 CHAN_TO_UBYTE(src
[BCOMP
]) );
2035 dstRow
+= dstRowStride
;
2038 free((void *) tempImage
);
2045 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2047 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2048 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2050 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2051 ASSERT(texelBytes
== 4);
2053 if (!ctx
->_ImageTransferState
&&
2054 !srcPacking
->SwapBytes
&&
2055 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2056 srcFormat
== GL_BGRA
&&
2057 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2058 baseInternalFormat
== GL_RGBA
) {
2059 /* simple memcpy path */
2060 memcpy_texture(ctx
, dims
,
2061 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2064 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2065 srcAddr
, srcPacking
);
2069 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2072 srcWidth
, srcHeight
, srcDepth
,
2073 srcFormat
, srcType
, srcAddr
,
2075 ctx
->_ImageTransferState
);
2076 const GLfloat
*src
= tempImage
;
2077 GLint img
, row
, col
;
2080 for (img
= 0; img
< srcDepth
; img
++) {
2081 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2082 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2083 + dstYoffset
* dstRowStride
2084 + dstXoffset
* texelBytes
;
2085 if (baseInternalFormat
== GL_RGBA
) {
2086 for (row
= 0; row
< srcHeight
; row
++) {
2087 GLuint
*dstUI
= (GLuint
*) dstRow
;
2088 for (col
= 0; col
< srcWidth
; col
++) {
2091 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2092 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2093 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2094 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2095 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2098 dstRow
+= dstRowStride
;
2100 } else if (baseInternalFormat
== GL_RGB
) {
2101 for (row
= 0; row
< srcHeight
; row
++) {
2102 GLuint
*dstUI
= (GLuint
*) dstRow
;
2103 for (col
= 0; col
< srcWidth
; col
++) {
2106 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2107 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2108 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2109 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2112 dstRow
+= dstRowStride
;
2118 free((void *) tempImage
);
2125 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2128 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2130 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2131 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2133 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2134 ASSERT(texelBytes
== 1);
2138 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2141 srcWidth
, srcHeight
, srcDepth
,
2142 srcFormat
, srcType
, srcAddr
,
2144 const GLchan
*src
= tempImage
;
2145 GLint img
, row
, col
;
2148 for (img
= 0; img
< srcDepth
; img
++) {
2149 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2150 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2151 + dstYoffset
* dstRowStride
2152 + dstXoffset
* texelBytes
;
2153 for (row
= 0; row
< srcHeight
; row
++) {
2154 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2155 for (col
= 0; col
< srcWidth
; col
++) {
2156 /* src[0] is luminance, src[1] is alpha */
2157 dstUS
[col
] = PACK_COLOR_44( CHAN_TO_UBYTE(src
[1]),
2158 CHAN_TO_UBYTE(src
[0]) );
2161 dstRow
+= dstRowStride
;
2164 free((void *) tempImage
);
2171 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2174 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2176 const GLboolean littleEndian
= _mesa_little_endian();
2177 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2178 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2180 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2181 dstFormat
== MESA_FORMAT_AL88_REV
||
2182 dstFormat
== MESA_FORMAT_RG88
||
2183 dstFormat
== MESA_FORMAT_RG88_REV
);
2184 ASSERT(texelBytes
== 2);
2186 if (!ctx
->_ImageTransferState
&&
2187 !srcPacking
->SwapBytes
&&
2188 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
2189 baseInternalFormat
== srcFormat
&&
2190 srcType
== GL_UNSIGNED_BYTE
&&
2192 /* simple memcpy path */
2193 memcpy_texture(ctx
, dims
,
2194 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2197 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2198 srcAddr
, srcPacking
);
2200 else if (!ctx
->_ImageTransferState
&&
2202 srcType
== GL_UNSIGNED_BYTE
&&
2203 can_swizzle(baseInternalFormat
) &&
2204 can_swizzle(srcFormat
)) {
2207 /* dstmap - how to swizzle from RGBA to dst format:
2209 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2210 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2211 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2221 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2222 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2231 dstmap
[2] = ZERO
; /* ? */
2232 dstmap
[3] = ONE
; /* ? */
2234 _mesa_swizzle_ubyte_image(ctx
, dims
,
2239 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2240 dstRowStride
, dstImageOffsets
,
2241 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2246 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2249 srcWidth
, srcHeight
, srcDepth
,
2250 srcFormat
, srcType
, srcAddr
,
2252 const GLchan
*src
= tempImage
;
2253 GLint img
, row
, col
;
2256 for (img
= 0; img
< srcDepth
; img
++) {
2257 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2258 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2259 + dstYoffset
* dstRowStride
2260 + dstXoffset
* texelBytes
;
2261 for (row
= 0; row
< srcHeight
; row
++) {
2262 GLushort
*dstUS
= (GLushort
*) dstRow
;
2263 if (dstFormat
== MESA_FORMAT_AL88
||
2264 dstFormat
== MESA_FORMAT_RG88
) {
2265 for (col
= 0; col
< srcWidth
; col
++) {
2266 /* src[0] is luminance, src[1] is alpha */
2267 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2268 CHAN_TO_UBYTE(src
[0]) );
2273 for (col
= 0; col
< srcWidth
; col
++) {
2274 /* src[0] is luminance, src[1] is alpha */
2275 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2276 CHAN_TO_UBYTE(src
[0]) );
2280 dstRow
+= dstRowStride
;
2283 free((void *) tempImage
);
2290 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2293 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2295 const GLboolean littleEndian
= _mesa_little_endian();
2296 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2297 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2299 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2300 dstFormat
== MESA_FORMAT_AL1616_REV
||
2301 dstFormat
== MESA_FORMAT_RG1616
||
2302 dstFormat
== MESA_FORMAT_RG1616_REV
);
2303 ASSERT(texelBytes
== 4);
2305 if (!ctx
->_ImageTransferState
&&
2306 !srcPacking
->SwapBytes
&&
2307 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2308 baseInternalFormat
== srcFormat
&&
2309 srcType
== GL_UNSIGNED_SHORT
&&
2311 /* simple memcpy path */
2312 memcpy_texture(ctx
, dims
,
2313 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2316 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2317 srcAddr
, srcPacking
);
2321 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2324 srcWidth
, srcHeight
, srcDepth
,
2325 srcFormat
, srcType
, srcAddr
,
2327 ctx
->_ImageTransferState
);
2328 const GLfloat
*src
= tempImage
;
2329 GLint img
, row
, col
;
2332 for (img
= 0; img
< srcDepth
; img
++) {
2333 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2334 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2335 + dstYoffset
* dstRowStride
2336 + dstXoffset
* texelBytes
;
2337 for (row
= 0; row
< srcHeight
; row
++) {
2338 GLuint
*dstUI
= (GLuint
*) dstRow
;
2339 if (dstFormat
== MESA_FORMAT_AL1616
||
2340 dstFormat
== MESA_FORMAT_RG1616
) {
2341 for (col
= 0; col
< srcWidth
; col
++) {
2344 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2345 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2346 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2351 for (col
= 0; col
< srcWidth
; col
++) {
2354 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2355 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2356 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2360 dstRow
+= dstRowStride
;
2363 free((void *) tempImage
);
2369 /* Texstore for R16, A16, L16, I16. */
2371 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2373 const GLboolean littleEndian
= _mesa_little_endian();
2374 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2375 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2377 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2378 dstFormat
== MESA_FORMAT_A16
||
2379 dstFormat
== MESA_FORMAT_L16
||
2380 dstFormat
== MESA_FORMAT_I16
);
2381 ASSERT(texelBytes
== 2);
2383 if (!ctx
->_ImageTransferState
&&
2384 !srcPacking
->SwapBytes
&&
2385 baseInternalFormat
== srcFormat
&&
2386 srcType
== GL_UNSIGNED_SHORT
&&
2388 /* simple memcpy path */
2389 memcpy_texture(ctx
, dims
,
2390 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2393 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2394 srcAddr
, srcPacking
);
2398 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2401 srcWidth
, srcHeight
, srcDepth
,
2402 srcFormat
, srcType
, srcAddr
,
2404 ctx
->_ImageTransferState
);
2405 const GLfloat
*src
= tempImage
;
2406 GLint img
, row
, col
;
2409 for (img
= 0; img
< srcDepth
; img
++) {
2410 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2411 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2412 + dstYoffset
* dstRowStride
2413 + dstXoffset
* texelBytes
;
2414 for (row
= 0; row
< srcHeight
; row
++) {
2415 GLushort
*dstUS
= (GLushort
*) dstRow
;
2416 for (col
= 0; col
< srcWidth
; col
++) {
2419 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2423 dstRow
+= dstRowStride
;
2426 free((void *) tempImage
);
2433 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2435 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2436 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2438 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2439 ASSERT(texelBytes
== 8);
2441 if (!ctx
->_ImageTransferState
&&
2442 !srcPacking
->SwapBytes
&&
2443 baseInternalFormat
== GL_RGBA
&&
2444 srcFormat
== GL_RGBA
&&
2445 srcType
== GL_UNSIGNED_SHORT
) {
2446 /* simple memcpy path */
2447 memcpy_texture(ctx
, dims
,
2448 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2451 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2452 srcAddr
, srcPacking
);
2456 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2459 srcWidth
, srcHeight
, srcDepth
,
2460 srcFormat
, srcType
, srcAddr
,
2462 ctx
->_ImageTransferState
);
2463 const GLfloat
*src
= tempImage
;
2464 GLint img
, row
, col
;
2467 for (img
= 0; img
< srcDepth
; img
++) {
2468 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2469 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2470 + dstYoffset
* dstRowStride
2471 + dstXoffset
* texelBytes
;
2472 for (row
= 0; row
< srcHeight
; row
++) {
2473 GLushort
*dstUS
= (GLushort
*) dstRow
;
2474 for (col
= 0; col
< srcWidth
; col
++) {
2475 GLushort r
, g
, b
, a
;
2477 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2478 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2479 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2480 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2487 dstRow
+= dstRowStride
;
2490 free((void *) tempImage
);
2497 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2499 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2500 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2502 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R_16
||
2503 dstFormat
== MESA_FORMAT_SIGNED_RG_16
||
2504 dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2505 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2507 if (!ctx
->_ImageTransferState
&&
2508 !srcPacking
->SwapBytes
&&
2509 baseInternalFormat
== GL_RGBA
&&
2510 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2511 srcFormat
== GL_RGBA
&&
2512 srcType
== GL_SHORT
) {
2513 /* simple memcpy path */
2514 memcpy_texture(ctx
, dims
,
2515 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2518 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2519 srcAddr
, srcPacking
);
2523 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2526 srcWidth
, srcHeight
, srcDepth
,
2527 srcFormat
, srcType
, srcAddr
,
2529 ctx
->_ImageTransferState
);
2530 const GLfloat
*src
= tempImage
;
2531 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2532 GLint img
, row
, col
;
2537 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2538 * 3 or 4 components/pixel here.
2540 for (img
= 0; img
< srcDepth
; img
++) {
2541 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2542 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2543 + dstYoffset
* dstRowStride
2544 + dstXoffset
* texelBytes
;
2545 for (row
= 0; row
< srcHeight
; row
++) {
2546 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2547 for (col
= 0; col
< srcWidth
; col
++) {
2549 for (c
= 0; c
< comps
; c
++) {
2551 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2552 dstRowS
[col
* comps
+ c
] = p
;
2555 dstRow
+= dstRowStride
;
2556 src
+= 4 * srcWidth
;
2559 free((void *) tempImage
);
2566 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2568 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2569 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2571 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2572 ASSERT(texelBytes
== 1);
2574 if (!ctx
->_ImageTransferState
&&
2575 !srcPacking
->SwapBytes
&&
2576 baseInternalFormat
== GL_RGB
&&
2577 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2578 /* simple memcpy path */
2579 memcpy_texture(ctx
, dims
,
2580 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2583 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2584 srcAddr
, srcPacking
);
2588 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2591 srcWidth
, srcHeight
, srcDepth
,
2592 srcFormat
, srcType
, srcAddr
,
2594 const GLchan
*src
= tempImage
;
2595 GLint img
, row
, col
;
2598 for (img
= 0; img
< srcDepth
; img
++) {
2599 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2600 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2601 + dstYoffset
* dstRowStride
2602 + dstXoffset
* texelBytes
;
2603 for (row
= 0; row
< srcHeight
; row
++) {
2604 for (col
= 0; col
< srcWidth
; col
++) {
2605 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2606 CHAN_TO_UBYTE(src
[GCOMP
]),
2607 CHAN_TO_UBYTE(src
[BCOMP
]) );
2610 dstRow
+= dstRowStride
;
2613 free((void *) tempImage
);
2620 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2623 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2625 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2626 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2628 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2629 dstFormat
== MESA_FORMAT_L8
||
2630 dstFormat
== MESA_FORMAT_I8
||
2631 dstFormat
== MESA_FORMAT_R8
);
2632 ASSERT(texelBytes
== 1);
2634 if (!ctx
->_ImageTransferState
&&
2635 !srcPacking
->SwapBytes
&&
2636 baseInternalFormat
== srcFormat
&&
2637 srcType
== GL_UNSIGNED_BYTE
) {
2638 /* simple memcpy path */
2639 memcpy_texture(ctx
, dims
,
2640 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2643 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2644 srcAddr
, srcPacking
);
2646 else if (!ctx
->_ImageTransferState
&&
2647 srcType
== GL_UNSIGNED_BYTE
&&
2648 can_swizzle(baseInternalFormat
) &&
2649 can_swizzle(srcFormat
)) {
2652 /* dstmap - how to swizzle from RGBA to dst format:
2654 if (dstFormat
== MESA_FORMAT_A8
) {
2660 dstmap
[1] = ZERO
; /* ? */
2661 dstmap
[2] = ZERO
; /* ? */
2662 dstmap
[3] = ONE
; /* ? */
2664 _mesa_swizzle_ubyte_image(ctx
, dims
,
2669 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2670 dstRowStride
, dstImageOffsets
,
2671 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2676 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2679 srcWidth
, srcHeight
, srcDepth
,
2680 srcFormat
, srcType
, srcAddr
,
2682 const GLchan
*src
= tempImage
;
2683 GLint img
, row
, col
;
2686 for (img
= 0; img
< srcDepth
; img
++) {
2687 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2688 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2689 + dstYoffset
* dstRowStride
2690 + dstXoffset
* texelBytes
;
2691 for (row
= 0; row
< srcHeight
; row
++) {
2692 for (col
= 0; col
< srcWidth
; col
++) {
2693 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2695 dstRow
+= dstRowStride
;
2699 free((void *) tempImage
);
2707 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2709 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2711 (void) dims
; (void) baseInternalFormat
;
2712 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2713 ASSERT(texelBytes
== 1);
2714 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2716 if (!ctx
->_ImageTransferState
&&
2717 !srcPacking
->SwapBytes
&&
2718 srcFormat
== GL_COLOR_INDEX
&&
2719 srcType
== GL_UNSIGNED_BYTE
) {
2720 /* simple memcpy path */
2721 memcpy_texture(ctx
, dims
,
2722 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2725 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2726 srcAddr
, srcPacking
);
2731 for (img
= 0; img
< srcDepth
; img
++) {
2732 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2733 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2734 + dstYoffset
* dstRowStride
2735 + dstXoffset
* texelBytes
;
2736 for (row
= 0; row
< srcHeight
; row
++) {
2737 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2738 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2739 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2740 srcType
, src
, srcPacking
,
2741 ctx
->_ImageTransferState
);
2742 dstRow
+= dstRowStride
;
2751 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2754 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2756 const GLboolean littleEndian
= _mesa_little_endian();
2757 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2759 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2761 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2762 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2763 ASSERT(texelBytes
== 2);
2764 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2765 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2766 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2767 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2768 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2770 /* always just memcpy since no pixel transfer ops apply */
2771 memcpy_texture(ctx
, dims
,
2772 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2775 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2776 srcAddr
, srcPacking
);
2778 /* Check if we need byte swapping */
2779 /* XXX the logic here _might_ be wrong */
2780 if (srcPacking
->SwapBytes
^
2781 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2782 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2785 for (img
= 0; img
< srcDepth
; img
++) {
2786 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2787 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2788 + dstYoffset
* dstRowStride
2789 + dstXoffset
* texelBytes
;
2790 for (row
= 0; row
< srcHeight
; row
++) {
2791 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2792 dstRow
+= dstRowStride
;
2800 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2802 const GLboolean littleEndian
= _mesa_little_endian();
2803 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2805 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2806 ASSERT(texelBytes
== 2);
2807 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2808 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2809 (srcFormat
== GL_DUDV_ATI
));
2810 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2812 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2814 /* simple memcpy path */
2815 memcpy_texture(ctx
, dims
,
2816 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2819 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2820 srcAddr
, srcPacking
);
2822 else if (srcType
== GL_BYTE
) {
2825 /* dstmap - how to swizzle from RGBA to dst format:
2835 dstmap
[2] = ZERO
; /* ? */
2836 dstmap
[3] = ONE
; /* ? */
2838 _mesa_swizzle_ubyte_image(ctx
, dims
,
2839 GL_LUMINANCE_ALPHA
, /* hack */
2840 GL_UNSIGNED_BYTE
, /* hack */
2841 GL_LUMINANCE_ALPHA
, /* hack */
2843 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2844 dstRowStride
, dstImageOffsets
,
2845 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2849 /* general path - note this is defined for 2d textures only */
2850 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2851 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2852 srcFormat
, srcType
);
2853 GLbyte
*tempImage
, *dst
, *src
;
2856 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2857 * components
* sizeof(GLbyte
));
2861 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2862 srcWidth
, srcHeight
,
2867 for (row
= 0; row
< srcHeight
; row
++) {
2868 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2869 dst
, srcFormat
, srcType
, src
,
2871 dst
+= srcWidth
* components
;
2876 dst
= (GLbyte
*) dstAddr
2877 + dstYoffset
* dstRowStride
2878 + dstXoffset
* texelBytes
;
2879 for (row
= 0; row
< srcHeight
; row
++) {
2880 memcpy(dst
, src
, srcWidth
* texelBytes
);
2881 dst
+= dstRowStride
;
2882 src
+= srcWidth
* texelBytes
;
2884 free((void *) tempImage
);
2891 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2894 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2896 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2897 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2899 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2900 ASSERT(texelBytes
== 1);
2902 /* XXX look at adding optimized paths */
2905 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2908 srcWidth
, srcHeight
, srcDepth
,
2909 srcFormat
, srcType
, srcAddr
,
2911 ctx
->_ImageTransferState
);
2912 const GLfloat
*srcRow
= tempImage
;
2913 GLint img
, row
, col
;
2916 for (img
= 0; img
< srcDepth
; img
++) {
2917 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2918 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2919 + dstYoffset
* dstRowStride
2920 + dstXoffset
* texelBytes
;
2921 for (row
= 0; row
< srcHeight
; row
++) {
2922 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2923 for (col
= 0; col
< srcWidth
; col
++) {
2924 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2926 dstRow
+= dstRowStride
;
2929 free((void *) tempImage
);
2936 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2939 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2941 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2942 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2944 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2945 ASSERT(texelBytes
== 1);
2947 /* XXX look at adding optimized paths */
2950 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2953 srcWidth
, srcHeight
, srcDepth
,
2954 srcFormat
, srcType
, srcAddr
,
2956 ctx
->_ImageTransferState
);
2957 const GLfloat
*srcRow
= tempImage
;
2958 GLint img
, row
, col
;
2961 for (img
= 0; img
< srcDepth
; img
++) {
2962 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2963 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2964 + dstYoffset
* dstRowStride
2965 + dstXoffset
* texelBytes
;
2966 for (row
= 0; row
< srcHeight
; row
++) {
2967 GLushort
*dstUS
= (GLushort
*) dstRow
;
2968 for (col
= 0; col
< srcWidth
; col
++) {
2969 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2970 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2972 dstRow
+= dstRowStride
;
2975 free((void *) tempImage
);
2982 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2985 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2987 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2988 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2990 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2991 ASSERT(texelBytes
== 4);
2995 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2998 srcWidth
, srcHeight
, srcDepth
,
2999 srcFormat
, srcType
, srcAddr
,
3001 ctx
->_ImageTransferState
);
3002 const GLfloat
*srcRow
= tempImage
;
3003 GLint img
, row
, col
;
3006 for (img
= 0; img
< srcDepth
; img
++) {
3007 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3008 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3009 + dstYoffset
* dstRowStride
3010 + dstXoffset
* texelBytes
;
3011 for (row
= 0; row
< srcHeight
; row
++) {
3012 GLuint
*dstUI
= (GLuint
*) dstRow
;
3013 for (col
= 0; col
< srcWidth
; col
++) {
3014 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3015 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3016 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3020 dstRow
+= dstRowStride
;
3023 free((void *) tempImage
);
3031 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3032 * MESA_FORMAT_SIGNED_RGBA8888_REV
3035 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3037 const GLboolean littleEndian
= _mesa_little_endian();
3038 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3039 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3041 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3042 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3043 ASSERT(texelBytes
== 4);
3045 if (!ctx
->_ImageTransferState
&&
3046 !srcPacking
->SwapBytes
&&
3047 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3048 baseInternalFormat
== GL_RGBA
&&
3049 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3050 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3051 /* simple memcpy path */
3052 memcpy_texture(ctx
, dims
,
3053 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3056 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3057 srcAddr
, srcPacking
);
3059 else if (!ctx
->_ImageTransferState
&&
3060 !srcPacking
->SwapBytes
&&
3061 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3062 baseInternalFormat
== GL_RGBA
&&
3063 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3064 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3065 /* simple memcpy path */
3066 memcpy_texture(ctx
, dims
,
3067 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3070 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3071 srcAddr
, srcPacking
);
3073 else if (!ctx
->_ImageTransferState
&&
3074 (srcType
== GL_BYTE
) &&
3075 can_swizzle(baseInternalFormat
) &&
3076 can_swizzle(srcFormat
)) {
3080 /* dstmap - how to swizzle from RGBA to dst format:
3082 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
3083 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
3096 _mesa_swizzle_ubyte_image(ctx
, dims
,
3101 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3102 dstRowStride
, dstImageOffsets
,
3103 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
3108 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3111 srcWidth
, srcHeight
, srcDepth
,
3112 srcFormat
, srcType
, srcAddr
,
3114 ctx
->_ImageTransferState
);
3115 const GLfloat
*srcRow
= tempImage
;
3116 GLint img
, row
, col
;
3119 for (img
= 0; img
< srcDepth
; img
++) {
3120 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3121 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3122 + dstYoffset
* dstRowStride
3123 + dstXoffset
* texelBytes
;
3124 for (row
= 0; row
< srcHeight
; row
++) {
3125 GLuint
*dstUI
= (GLuint
*) dstRow
;
3126 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3127 for (col
= 0; col
< srcWidth
; col
++) {
3128 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3129 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3130 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3131 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3136 for (col
= 0; col
< srcWidth
; col
++) {
3137 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3138 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3139 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3140 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3144 dstRow
+= dstRowStride
;
3147 free((void *) tempImage
);
3154 * Store a combined depth/stencil texture image.
3157 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3159 const GLuint depthScale
= 0xffffff;
3160 const GLint srcRowStride
3161 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3165 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3166 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
3167 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3169 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3170 ctx
->Pixel
.DepthBias
== 0.0f
&&
3171 !srcPacking
->SwapBytes
) {
3173 memcpy_texture(ctx
, dims
,
3174 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3177 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3178 srcAddr
, srcPacking
);
3180 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
3181 /* In case we only upload depth we need to preserve the stencil */
3182 for (img
= 0; img
< srcDepth
; img
++) {
3183 GLuint
*dstRow
= (GLuint
*) dstAddr
3184 + dstImageOffsets
[dstZoffset
+ img
]
3185 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3188 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3189 srcWidth
, srcHeight
,
3192 for (row
= 0; row
< srcHeight
; row
++) {
3193 GLuint depth
[MAX_WIDTH
];
3194 GLubyte stencil
[MAX_WIDTH
];
3196 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3198 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3199 keepstencil
= GL_TRUE
;
3201 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3202 keepdepth
= GL_TRUE
;
3205 if (keepdepth
== GL_FALSE
)
3206 /* the 24 depth bits will be in the low position: */
3207 _mesa_unpack_depth_span(ctx
, srcWidth
,
3208 GL_UNSIGNED_INT
, /* dst type */
3209 keepstencil
? depth
: dstRow
, /* dst addr */
3211 srcType
, src
, srcPacking
);
3213 if (keepstencil
== GL_FALSE
)
3214 /* get the 8-bit stencil values */
3215 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3216 GL_UNSIGNED_BYTE
, /* dst type */
3217 stencil
, /* dst addr */
3218 srcType
, src
, srcPacking
,
3219 ctx
->_ImageTransferState
);
3221 for (i
= 0; i
< srcWidth
; i
++) {
3223 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3225 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3228 src
+= srcRowStride
;
3229 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3238 * Store a combined depth/stencil texture image.
3241 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3243 const GLuint depthScale
= 0xffffff;
3244 const GLint srcRowStride
3245 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3249 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3250 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3251 srcFormat
== GL_DEPTH_COMPONENT
||
3252 srcFormat
== GL_STENCIL_INDEX
);
3253 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3254 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3256 for (img
= 0; img
< srcDepth
; img
++) {
3257 GLuint
*dstRow
= (GLuint
*) dstAddr
3258 + dstImageOffsets
[dstZoffset
+ img
]
3259 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3262 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3263 srcWidth
, srcHeight
,
3266 for (row
= 0; row
< srcHeight
; row
++) {
3267 GLuint depth
[MAX_WIDTH
];
3268 GLubyte stencil
[MAX_WIDTH
];
3270 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3272 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3273 keepstencil
= GL_TRUE
;
3275 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3276 keepdepth
= GL_TRUE
;
3279 if (keepdepth
== GL_FALSE
)
3280 /* the 24 depth bits will be in the low position: */
3281 _mesa_unpack_depth_span(ctx
, srcWidth
,
3282 GL_UNSIGNED_INT
, /* dst type */
3283 keepstencil
? depth
: dstRow
, /* dst addr */
3285 srcType
, src
, srcPacking
);
3287 if (keepstencil
== GL_FALSE
)
3288 /* get the 8-bit stencil values */
3289 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3290 GL_UNSIGNED_BYTE
, /* dst type */
3291 stencil
, /* dst addr */
3292 srcType
, src
, srcPacking
,
3293 ctx
->_ImageTransferState
);
3295 /* merge stencil values into depth values */
3296 for (i
= 0; i
< srcWidth
; i
++) {
3298 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3300 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3303 src
+= srcRowStride
;
3304 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3312 * Store simple 8-bit/value stencil texture data.
3315 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3317 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3318 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3320 if (!ctx
->_ImageTransferState
&&
3321 !srcPacking
->SwapBytes
&&
3322 baseInternalFormat
== srcFormat
&&
3323 srcType
== GL_UNSIGNED_BYTE
) {
3324 /* simple memcpy path */
3325 memcpy_texture(ctx
, dims
,
3326 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3329 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3330 srcAddr
, srcPacking
);
3333 const GLint srcRowStride
3334 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3338 for (img
= 0; img
< srcDepth
; img
++) {
3339 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3340 + dstImageOffsets
[dstZoffset
+ img
]
3341 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3344 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3345 srcWidth
, srcHeight
,
3348 for (row
= 0; row
< srcHeight
; row
++) {
3349 GLubyte stencil
[MAX_WIDTH
];
3352 /* get the 8-bit stencil values */
3353 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3354 GL_UNSIGNED_BYTE
, /* dst type */
3355 stencil
, /* dst addr */
3356 srcType
, src
, srcPacking
,
3357 ctx
->_ImageTransferState
);
3358 /* merge stencil values into depth values */
3359 for (i
= 0; i
< srcWidth
; i
++)
3360 dstRow
[i
] = stencil
[i
];
3362 src
+= srcRowStride
;
3363 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3374 * Store an image in any of the formats:
3375 * _mesa_texformat_rgba_float32
3376 * _mesa_texformat_rgb_float32
3377 * _mesa_texformat_alpha_float32
3378 * _mesa_texformat_luminance_float32
3379 * _mesa_texformat_luminance_alpha_float32
3380 * _mesa_texformat_intensity_float32
3383 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3385 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3386 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3387 const GLint components
= _mesa_components_in_format(baseFormat
);
3389 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3390 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3391 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3392 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3393 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3394 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3395 ASSERT(baseInternalFormat
== GL_RGBA
||
3396 baseInternalFormat
== GL_RGB
||
3397 baseInternalFormat
== GL_ALPHA
||
3398 baseInternalFormat
== GL_LUMINANCE
||
3399 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3400 baseInternalFormat
== GL_INTENSITY
);
3401 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3403 if (!ctx
->_ImageTransferState
&&
3404 !srcPacking
->SwapBytes
&&
3405 baseInternalFormat
== srcFormat
&&
3406 srcType
== GL_FLOAT
) {
3407 /* simple memcpy path */
3408 memcpy_texture(ctx
, dims
,
3409 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3412 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3413 srcAddr
, srcPacking
);
3417 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3420 srcWidth
, srcHeight
, srcDepth
,
3421 srcFormat
, srcType
, srcAddr
,
3423 ctx
->_ImageTransferState
);
3424 const GLfloat
*srcRow
= tempImage
;
3429 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3430 for (img
= 0; img
< srcDepth
; img
++) {
3431 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3432 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3433 + dstYoffset
* dstRowStride
3434 + dstXoffset
* texelBytes
;
3435 for (row
= 0; row
< srcHeight
; row
++) {
3436 memcpy(dstRow
, srcRow
, bytesPerRow
);
3437 dstRow
+= dstRowStride
;
3438 srcRow
+= srcWidth
* components
;
3442 free((void *) tempImage
);
3450 * As above, but store 16-bit floats.
3453 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3455 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3456 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3457 const GLint components
= _mesa_components_in_format(baseFormat
);
3459 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3460 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3461 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3462 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3463 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3464 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3465 ASSERT(baseInternalFormat
== GL_RGBA
||
3466 baseInternalFormat
== GL_RGB
||
3467 baseInternalFormat
== GL_ALPHA
||
3468 baseInternalFormat
== GL_LUMINANCE
||
3469 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3470 baseInternalFormat
== GL_INTENSITY
);
3471 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3473 if (!ctx
->_ImageTransferState
&&
3474 !srcPacking
->SwapBytes
&&
3475 baseInternalFormat
== srcFormat
&&
3476 srcType
== GL_HALF_FLOAT_ARB
) {
3477 /* simple memcpy path */
3478 memcpy_texture(ctx
, dims
,
3479 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3482 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3483 srcAddr
, srcPacking
);
3487 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3490 srcWidth
, srcHeight
, srcDepth
,
3491 srcFormat
, srcType
, srcAddr
,
3493 ctx
->_ImageTransferState
);
3494 const GLfloat
*src
= tempImage
;
3498 for (img
= 0; img
< srcDepth
; img
++) {
3499 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3500 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3501 + dstYoffset
* dstRowStride
3502 + dstXoffset
* texelBytes
;
3503 for (row
= 0; row
< srcHeight
; row
++) {
3504 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3506 for (i
= 0; i
< srcWidth
* components
; i
++) {
3507 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3509 dstRow
+= dstRowStride
;
3510 src
+= srcWidth
* components
;
3514 free((void *) tempImage
);
3520 /* non-normalized, signed int8 */
3522 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3524 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3525 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3526 const GLint components
= _mesa_components_in_format(baseFormat
);
3528 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3529 ASSERT(baseInternalFormat
== GL_RGBA
||
3530 baseInternalFormat
== GL_RGB
||
3531 baseInternalFormat
== GL_ALPHA
||
3532 baseInternalFormat
== GL_LUMINANCE
||
3533 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3534 baseInternalFormat
== GL_INTENSITY
);
3535 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3537 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3538 * to integer formats.
3540 if (!srcPacking
->SwapBytes
&&
3541 baseInternalFormat
== srcFormat
&&
3542 srcType
== GL_BYTE
) {
3543 /* simple memcpy path */
3544 memcpy_texture(ctx
, dims
,
3545 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3548 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3549 srcAddr
, srcPacking
);
3553 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3556 srcWidth
, srcHeight
, srcDepth
,
3557 srcFormat
, srcType
, srcAddr
,
3559 const GLfloat
*src
= tempImage
;
3563 for (img
= 0; img
< srcDepth
; img
++) {
3564 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3565 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3566 + dstYoffset
* dstRowStride
3567 + dstXoffset
* texelBytes
;
3568 for (row
= 0; row
< srcHeight
; row
++) {
3569 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3571 for (i
= 0; i
< srcWidth
* components
; i
++) {
3572 dstTexel
[i
] = (GLbyte
) src
[i
];
3574 dstRow
+= dstRowStride
;
3575 src
+= srcWidth
* components
;
3579 free((void *) tempImage
);
3585 /* non-normalized, signed int16 */
3587 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3589 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3590 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3591 const GLint components
= _mesa_components_in_format(baseFormat
);
3593 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3594 ASSERT(baseInternalFormat
== GL_RGBA
||
3595 baseInternalFormat
== GL_RGB
||
3596 baseInternalFormat
== GL_ALPHA
||
3597 baseInternalFormat
== GL_LUMINANCE
||
3598 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3599 baseInternalFormat
== GL_INTENSITY
);
3600 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3602 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3603 * to integer formats.
3605 if (!srcPacking
->SwapBytes
&&
3606 baseInternalFormat
== srcFormat
&&
3607 srcType
== GL_SHORT
) {
3608 /* simple memcpy path */
3609 memcpy_texture(ctx
, dims
,
3610 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3613 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3614 srcAddr
, srcPacking
);
3618 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3621 srcWidth
, srcHeight
, srcDepth
,
3622 srcFormat
, srcType
, srcAddr
,
3624 const GLfloat
*src
= tempImage
;
3628 for (img
= 0; img
< srcDepth
; img
++) {
3629 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3630 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3631 + dstYoffset
* dstRowStride
3632 + dstXoffset
* texelBytes
;
3633 for (row
= 0; row
< srcHeight
; row
++) {
3634 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3636 for (i
= 0; i
< srcWidth
* components
; i
++) {
3637 dstTexel
[i
] = (GLint
) src
[i
];
3639 dstRow
+= dstRowStride
;
3640 src
+= srcWidth
* components
;
3644 free((void *) tempImage
);
3650 /* non-normalized, signed int32 */
3652 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3654 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3655 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3656 const GLint components
= _mesa_components_in_format(baseFormat
);
3658 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3659 ASSERT(baseInternalFormat
== GL_RGBA
||
3660 baseInternalFormat
== GL_RGB
||
3661 baseInternalFormat
== GL_ALPHA
||
3662 baseInternalFormat
== GL_LUMINANCE
||
3663 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3664 baseInternalFormat
== GL_INTENSITY
);
3665 ASSERT(texelBytes
== components
* sizeof(GLint
));
3667 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3668 * to integer formats.
3670 if (!srcPacking
->SwapBytes
&&
3671 baseInternalFormat
== srcFormat
&&
3672 srcType
== GL_INT
) {
3673 /* simple memcpy path */
3674 memcpy_texture(ctx
, dims
,
3675 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3678 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3679 srcAddr
, srcPacking
);
3683 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3686 srcWidth
, srcHeight
, srcDepth
,
3687 srcFormat
, srcType
, srcAddr
,
3689 const GLfloat
*src
= tempImage
;
3693 for (img
= 0; img
< srcDepth
; img
++) {
3694 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3695 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3696 + dstYoffset
* dstRowStride
3697 + dstXoffset
* texelBytes
;
3698 for (row
= 0; row
< srcHeight
; row
++) {
3699 GLint
*dstTexel
= (GLint
*) dstRow
;
3701 for (i
= 0; i
< srcWidth
* components
; i
++) {
3702 dstTexel
[i
] = (GLint
) src
[i
];
3704 dstRow
+= dstRowStride
;
3705 src
+= srcWidth
* components
;
3709 free((void *) tempImage
);
3715 /* non-normalized, unsigned int8 */
3717 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3719 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3720 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3721 const GLint components
= _mesa_components_in_format(baseFormat
);
3723 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3724 ASSERT(baseInternalFormat
== GL_RGBA
||
3725 baseInternalFormat
== GL_RGB
||
3726 baseInternalFormat
== GL_ALPHA
||
3727 baseInternalFormat
== GL_LUMINANCE
||
3728 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3729 baseInternalFormat
== GL_INTENSITY
);
3730 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3732 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3733 * to integer formats.
3735 if (!srcPacking
->SwapBytes
&&
3736 baseInternalFormat
== srcFormat
&&
3737 srcType
== GL_UNSIGNED_BYTE
) {
3738 /* simple memcpy path */
3739 memcpy_texture(ctx
, dims
,
3740 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3743 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3744 srcAddr
, srcPacking
);
3748 const GLuint
*tempImage
=
3749 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3750 srcWidth
, srcHeight
, srcDepth
,
3751 srcFormat
, srcType
, srcAddr
, srcPacking
);
3752 const GLuint
*src
= tempImage
;
3756 for (img
= 0; img
< srcDepth
; img
++) {
3757 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3758 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3759 + dstYoffset
* dstRowStride
3760 + dstXoffset
* texelBytes
;
3761 for (row
= 0; row
< srcHeight
; row
++) {
3762 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3764 for (i
= 0; i
< srcWidth
* components
; i
++) {
3765 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3767 dstRow
+= dstRowStride
;
3768 src
+= srcWidth
* components
;
3772 free((void *) tempImage
);
3778 /* non-normalized, unsigned int16 */
3780 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3782 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3783 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3784 const GLint components
= _mesa_components_in_format(baseFormat
);
3786 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3787 ASSERT(baseInternalFormat
== GL_RGBA
||
3788 baseInternalFormat
== GL_RGB
||
3789 baseInternalFormat
== GL_ALPHA
||
3790 baseInternalFormat
== GL_LUMINANCE
||
3791 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3792 baseInternalFormat
== GL_INTENSITY
);
3793 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3795 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3796 * to integer formats.
3798 if (!srcPacking
->SwapBytes
&&
3799 baseInternalFormat
== srcFormat
&&
3800 srcType
== GL_UNSIGNED_SHORT
) {
3801 /* simple memcpy path */
3802 memcpy_texture(ctx
, dims
,
3803 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3806 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3807 srcAddr
, srcPacking
);
3811 const GLuint
*tempImage
=
3812 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3813 srcWidth
, srcHeight
, srcDepth
,
3814 srcFormat
, srcType
, srcAddr
, srcPacking
);
3815 const GLuint
*src
= tempImage
;
3819 for (img
= 0; img
< srcDepth
; img
++) {
3820 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3821 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3822 + dstYoffset
* dstRowStride
3823 + dstXoffset
* texelBytes
;
3824 for (row
= 0; row
< srcHeight
; row
++) {
3825 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3827 for (i
= 0; i
< srcWidth
* components
; i
++) {
3828 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3830 dstRow
+= dstRowStride
;
3831 src
+= srcWidth
* components
;
3835 free((void *) tempImage
);
3841 /* non-normalized, unsigned int32 */
3843 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3845 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3846 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3847 const GLint components
= _mesa_components_in_format(baseFormat
);
3849 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3850 ASSERT(baseInternalFormat
== GL_RGBA
||
3851 baseInternalFormat
== GL_RGB
||
3852 baseInternalFormat
== GL_ALPHA
||
3853 baseInternalFormat
== GL_LUMINANCE
||
3854 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3855 baseInternalFormat
== GL_INTENSITY
);
3856 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3858 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3859 * to integer formats.
3861 if (!srcPacking
->SwapBytes
&&
3862 baseInternalFormat
== srcFormat
&&
3863 srcType
== GL_UNSIGNED_INT
) {
3864 /* simple memcpy path */
3865 memcpy_texture(ctx
, dims
,
3866 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3869 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3870 srcAddr
, srcPacking
);
3874 const GLuint
*tempImage
=
3875 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3876 srcWidth
, srcHeight
, srcDepth
,
3877 srcFormat
, srcType
, srcAddr
, srcPacking
);
3878 const GLuint
*src
= tempImage
;
3882 for (img
= 0; img
< srcDepth
; img
++) {
3883 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3884 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3885 + dstYoffset
* dstRowStride
3886 + dstXoffset
* texelBytes
;
3887 for (row
= 0; row
< srcHeight
; row
++) {
3888 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3890 for (i
= 0; i
< srcWidth
* components
; i
++) {
3891 dstTexel
[i
] = src
[i
];
3893 dstRow
+= dstRowStride
;
3894 src
+= srcWidth
* components
;
3898 free((void *) tempImage
);
3906 #if FEATURE_EXT_texture_sRGB
3908 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3910 gl_format newDstFormat
;
3913 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3915 /* reuse normal rgb texstore code */
3916 newDstFormat
= MESA_FORMAT_RGB888
;
3918 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3919 newDstFormat
, dstAddr
,
3920 dstXoffset
, dstYoffset
, dstZoffset
,
3921 dstRowStride
, dstImageOffsets
,
3922 srcWidth
, srcHeight
, srcDepth
,
3924 srcAddr
, srcPacking
);
3930 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3932 gl_format newDstFormat
;
3935 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3937 /* reuse normal rgba texstore code */
3938 newDstFormat
= MESA_FORMAT_RGBA8888
;
3939 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3940 newDstFormat
, dstAddr
,
3941 dstXoffset
, dstYoffset
, dstZoffset
,
3942 dstRowStride
, dstImageOffsets
,
3943 srcWidth
, srcHeight
, srcDepth
,
3945 srcAddr
, srcPacking
);
3951 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3953 gl_format newDstFormat
;
3956 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3958 /* reuse normal rgba texstore code */
3959 newDstFormat
= MESA_FORMAT_ARGB8888
;
3961 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3962 newDstFormat
, dstAddr
,
3963 dstXoffset
, dstYoffset
, dstZoffset
,
3964 dstRowStride
, dstImageOffsets
,
3965 srcWidth
, srcHeight
, srcDepth
,
3967 srcAddr
, srcPacking
);
3973 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3975 gl_format newDstFormat
;
3978 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3980 newDstFormat
= MESA_FORMAT_L8
;
3982 /* _mesa_textore_a8 handles luminance8 too */
3983 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3984 newDstFormat
, dstAddr
,
3985 dstXoffset
, dstYoffset
, dstZoffset
,
3986 dstRowStride
, dstImageOffsets
,
3987 srcWidth
, srcHeight
, srcDepth
,
3989 srcAddr
, srcPacking
);
3995 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3997 gl_format newDstFormat
;
4000 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4002 /* reuse normal luminance/alpha texstore code */
4003 newDstFormat
= MESA_FORMAT_AL88
;
4005 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4006 newDstFormat
, dstAddr
,
4007 dstXoffset
, dstYoffset
, dstZoffset
,
4008 dstRowStride
, dstImageOffsets
,
4009 srcWidth
, srcHeight
, srcDepth
,
4011 srcAddr
, srcPacking
);
4017 /* these are used only in texstore_funcs[] below */
4018 #define _mesa_texstore_srgb8 NULL
4019 #define _mesa_texstore_srgba8 NULL
4020 #define _mesa_texstore_sargb8 NULL
4021 #define _mesa_texstore_sl8 NULL
4022 #define _mesa_texstore_sla8 NULL
4024 #endif /* FEATURE_EXT_texture_sRGB */
4030 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4031 * XXX this is somewhat temporary.
4033 static const struct {
4035 StoreTexImageFunc Store
;
4037 texstore_funcs
[MESA_FORMAT_COUNT
] =
4039 { MESA_FORMAT_NONE
, NULL
},
4040 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
4041 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
4042 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
4043 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
4044 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
4045 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
4046 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
4047 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
4048 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
4049 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
4050 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
4051 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
4052 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
4053 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
4054 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
4055 { MESA_FORMAT_AL44
, _mesa_texstore_unorm44
},
4056 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
4057 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
4058 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
4059 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
4060 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
4061 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
4062 { MESA_FORMAT_A16
, _mesa_texstore_unorm16
},
4063 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
4064 { MESA_FORMAT_L16
, _mesa_texstore_unorm16
},
4065 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
4066 { MESA_FORMAT_I16
, _mesa_texstore_unorm16
},
4067 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
4068 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
4069 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
4070 { MESA_FORMAT_R8
, _mesa_texstore_a8
},
4071 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
4072 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
4073 { MESA_FORMAT_R16
, _mesa_texstore_unorm16
},
4074 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
4075 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
4076 { MESA_FORMAT_ARGB2101010
, _mesa_texstore_argb2101010
},
4077 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
4078 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
4079 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
4080 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
4081 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
4082 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
4083 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
4084 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
4085 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
4086 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
4087 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
4088 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
4089 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4090 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4091 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4092 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4093 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
4094 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
4095 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4096 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4097 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4098 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4099 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
4100 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
4101 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
4102 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
4103 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4104 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4105 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
4106 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
4107 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4108 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4109 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
4110 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
4112 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
4113 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
4114 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
4115 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
4116 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
4117 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
4119 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
4121 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
4122 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
4123 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
4125 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
4126 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
4128 { MESA_FORMAT_SIGNED_R_16
, _mesa_texstore_signed_rgba_16
},
4129 { MESA_FORMAT_SIGNED_RG_16
, _mesa_texstore_signed_rgba_16
},
4130 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
4131 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
4132 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
},
4134 { MESA_FORMAT_RED_RGTC1
, _mesa_texstore_red_rgtc1
},
4135 { MESA_FORMAT_SIGNED_RED_RGTC1
, _mesa_texstore_signed_red_rgtc1
},
4136 { MESA_FORMAT_RG_RGTC2
, _mesa_texstore_rg_rgtc2
},
4137 { MESA_FORMAT_SIGNED_RG_RGTC2
, _mesa_texstore_signed_rg_rgtc2
}
4142 _mesa_texstore_null(TEXSTORE_PARAMS
)
4144 (void) ctx
; (void) dims
;
4145 (void) baseInternalFormat
;
4148 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4149 (void) dstRowStride
; (void) dstImageOffsets
;
4150 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4151 (void) srcFormat
; (void) srcType
;
4155 /* should never happen */
4156 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4162 * Return the StoreTexImageFunc pointer to store an image in the given format.
4164 static StoreTexImageFunc
4165 _mesa_get_texstore_func(gl_format format
)
4169 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4170 ASSERT(texstore_funcs
[i
].Name
== i
);
4173 ASSERT(texstore_funcs
[format
].Name
== format
);
4175 if (texstore_funcs
[format
].Store
)
4176 return texstore_funcs
[format
].Store
;
4178 return _mesa_texstore_null
;
4183 * Store user data into texture memory.
4184 * Called via glTex[Sub]Image1/2/3D()
4187 _mesa_texstore(TEXSTORE_PARAMS
)
4189 StoreTexImageFunc storeImage
;
4192 storeImage
= _mesa_get_texstore_func(dstFormat
);
4194 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4195 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4196 dstRowStride
, dstImageOffsets
,
4197 srcWidth
, srcHeight
, srcDepth
,
4198 srcFormat
, srcType
, srcAddr
, srcPacking
);
4204 * Check if an unpack PBO is active prior to fetching a texture image.
4205 * If so, do bounds checking and map the buffer into main memory.
4206 * Any errors detected will be recorded.
4207 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4210 _mesa_validate_pbo_teximage(struct gl_context
*ctx
, GLuint dimensions
,
4211 GLsizei width
, GLsizei height
, GLsizei depth
,
4212 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4213 const struct gl_pixelstore_attrib
*unpack
,
4214 const char *funcName
)
4218 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
4222 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
4223 format
, type
, pixels
)) {
4224 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4228 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4229 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
4231 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped)");
4235 return ADD_POINTERS(buf
, pixels
);
4240 * Check if an unpack PBO is active prior to fetching a compressed texture
4242 * If so, do bounds checking and map the buffer into main memory.
4243 * Any errors detected will be recorded.
4244 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4247 _mesa_validate_pbo_compressed_teximage(struct gl_context
*ctx
,
4248 GLsizei imageSize
, const GLvoid
*pixels
,
4249 const struct gl_pixelstore_attrib
*packing
,
4250 const char *funcName
)
4254 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
4255 /* not using a PBO - return pointer unchanged */
4258 if ((const GLubyte
*) pixels
+ imageSize
>
4259 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
4260 /* out of bounds read! */
4261 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4265 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4266 GL_READ_ONLY_ARB
, packing
->BufferObj
);
4268 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
4272 return ADD_POINTERS(buf
, pixels
);
4277 * This function must be called after either of the validate_pbo_*_teximage()
4278 * functions. It unmaps the PBO buffer if it was mapped earlier.
4281 _mesa_unmap_teximage_pbo(struct gl_context
*ctx
,
4282 const struct gl_pixelstore_attrib
*unpack
)
4284 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
4285 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4291 /** Return texture size in bytes */
4293 texture_size(const struct gl_texture_image
*texImage
)
4295 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4296 texImage
->Height
, texImage
->Depth
);
4301 /** Return row stride in bytes */
4303 texture_row_stride(const struct gl_texture_image
*texImage
)
4305 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4313 * This is the software fallback for Driver.TexImage1D()
4314 * and Driver.CopyTexImage1D().
4315 * \sa _mesa_store_teximage2d()
4318 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4319 GLint internalFormat
,
4320 GLint width
, GLint border
,
4321 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4322 const struct gl_pixelstore_attrib
*packing
,
4323 struct gl_texture_object
*texObj
,
4324 struct gl_texture_image
*texImage
)
4329 /* allocate memory */
4330 sizeInBytes
= texture_size(texImage
);
4331 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4332 if (!texImage
->Data
) {
4333 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4337 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4338 pixels
, packing
, "glTexImage1D");
4340 /* Note: we check for a NULL image pointer here, _after_ we allocated
4341 * memory for the texture. That's what the GL spec calls for.
4346 const GLint dstRowStride
= 0;
4347 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4348 texImage
->TexFormat
,
4350 0, 0, 0, /* dstX/Y/Zoffset */
4352 texImage
->ImageOffsets
,
4354 format
, type
, pixels
, packing
);
4356 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4360 _mesa_unmap_teximage_pbo(ctx
, packing
);
4365 * This is the software fallback for Driver.TexImage2D()
4366 * and Driver.CopyTexImage2D().
4368 * This function is oriented toward storing images in main memory, rather
4369 * than VRAM. Device driver's can easily plug in their own replacement.
4372 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4373 GLint internalFormat
,
4374 GLint width
, GLint height
, GLint border
,
4375 GLenum format
, GLenum type
, const void *pixels
,
4376 const struct gl_pixelstore_attrib
*packing
,
4377 struct gl_texture_object
*texObj
,
4378 struct gl_texture_image
*texImage
)
4383 /* allocate memory */
4384 sizeInBytes
= texture_size(texImage
);
4385 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4386 if (!texImage
->Data
) {
4387 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4391 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4392 pixels
, packing
, "glTexImage2D");
4394 /* Note: we check for a NULL image pointer here, _after_ we allocated
4395 * memory for the texture. That's what the GL spec calls for.
4400 GLint dstRowStride
= texture_row_stride(texImage
);
4401 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4402 texImage
->TexFormat
,
4404 0, 0, 0, /* dstX/Y/Zoffset */
4406 texImage
->ImageOffsets
,
4408 format
, type
, pixels
, packing
);
4410 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4414 _mesa_unmap_teximage_pbo(ctx
, packing
);
4420 * This is the software fallback for Driver.TexImage3D()
4421 * and Driver.CopyTexImage3D().
4422 * \sa _mesa_store_teximage2d()
4425 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4426 GLint internalFormat
,
4427 GLint width
, GLint height
, GLint depth
, GLint border
,
4428 GLenum format
, GLenum type
, const void *pixels
,
4429 const struct gl_pixelstore_attrib
*packing
,
4430 struct gl_texture_object
*texObj
,
4431 struct gl_texture_image
*texImage
)
4436 /* allocate memory */
4437 sizeInBytes
= texture_size(texImage
);
4438 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4439 if (!texImage
->Data
) {
4440 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4444 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4445 type
, pixels
, packing
, "glTexImage3D");
4447 /* Note: we check for a NULL image pointer here, _after_ we allocated
4448 * memory for the texture. That's what the GL spec calls for.
4453 GLint dstRowStride
= texture_row_stride(texImage
);
4454 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4455 texImage
->TexFormat
,
4457 0, 0, 0, /* dstX/Y/Zoffset */
4459 texImage
->ImageOffsets
,
4460 width
, height
, depth
,
4461 format
, type
, pixels
, packing
);
4463 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4467 _mesa_unmap_teximage_pbo(ctx
, packing
);
4474 * This is the software fallback for Driver.TexSubImage1D()
4475 * and Driver.CopyTexSubImage1D().
4478 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4479 GLint xoffset
, GLint width
,
4480 GLenum format
, GLenum type
, const void *pixels
,
4481 const struct gl_pixelstore_attrib
*packing
,
4482 struct gl_texture_object
*texObj
,
4483 struct gl_texture_image
*texImage
)
4485 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4486 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4487 pixels
, packing
, "glTexSubImage1D");
4492 const GLint dstRowStride
= 0;
4493 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4494 texImage
->TexFormat
,
4496 xoffset
, 0, 0, /* offsets */
4498 texImage
->ImageOffsets
,
4500 format
, type
, pixels
, packing
);
4502 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4506 _mesa_unmap_teximage_pbo(ctx
, packing
);
4512 * This is the software fallback for Driver.TexSubImage2D()
4513 * and Driver.CopyTexSubImage2D().
4516 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4517 GLint xoffset
, GLint yoffset
,
4518 GLint width
, GLint height
,
4519 GLenum format
, GLenum type
, const void *pixels
,
4520 const struct gl_pixelstore_attrib
*packing
,
4521 struct gl_texture_object
*texObj
,
4522 struct gl_texture_image
*texImage
)
4524 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4525 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4526 pixels
, packing
, "glTexSubImage2D");
4531 GLint dstRowStride
= texture_row_stride(texImage
);
4532 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4533 texImage
->TexFormat
,
4535 xoffset
, yoffset
, 0,
4537 texImage
->ImageOffsets
,
4539 format
, type
, pixels
, packing
);
4541 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4545 _mesa_unmap_teximage_pbo(ctx
, packing
);
4550 * This is the software fallback for Driver.TexSubImage3D().
4551 * and Driver.CopyTexSubImage3D().
4554 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4555 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4556 GLint width
, GLint height
, GLint depth
,
4557 GLenum format
, GLenum type
, const void *pixels
,
4558 const struct gl_pixelstore_attrib
*packing
,
4559 struct gl_texture_object
*texObj
,
4560 struct gl_texture_image
*texImage
)
4562 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4563 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4564 type
, pixels
, packing
,
4570 GLint dstRowStride
= texture_row_stride(texImage
);
4571 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4572 texImage
->TexFormat
,
4574 xoffset
, yoffset
, zoffset
,
4576 texImage
->ImageOffsets
,
4577 width
, height
, depth
,
4578 format
, type
, pixels
, packing
);
4580 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4584 _mesa_unmap_teximage_pbo(ctx
, packing
);
4589 * Fallback for Driver.CompressedTexImage1D()
4592 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4593 GLenum target
, GLint level
,
4594 GLint internalFormat
,
4595 GLint width
, GLint border
,
4596 GLsizei imageSize
, const GLvoid
*data
,
4597 struct gl_texture_object
*texObj
,
4598 struct gl_texture_image
*texImage
)
4600 /* this space intentionally left blank */
4602 (void) target
; (void) level
;
4603 (void) internalFormat
;
4604 (void) width
; (void) border
;
4605 (void) imageSize
; (void) data
;
4613 * Fallback for Driver.CompressedTexImage2D()
4616 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4617 GLenum target
, GLint level
,
4618 GLint internalFormat
,
4619 GLint width
, GLint height
, GLint border
,
4620 GLsizei imageSize
, const GLvoid
*data
,
4621 struct gl_texture_object
*texObj
,
4622 struct gl_texture_image
*texImage
)
4624 (void) width
; (void) height
; (void) border
;
4626 /* This is pretty simple, basically just do a memcpy without worrying
4627 * about the usual image unpacking or image transfer operations.
4631 ASSERT(texImage
->Width
> 0);
4632 ASSERT(texImage
->Height
> 0);
4633 ASSERT(texImage
->Depth
== 1);
4634 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4636 /* allocate storage */
4637 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4638 if (!texImage
->Data
) {
4639 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4643 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4645 "glCompressedTexImage2D");
4650 memcpy(texImage
->Data
, data
, imageSize
);
4652 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4658 * Fallback for Driver.CompressedTexImage3D()
4661 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4662 GLenum target
, GLint level
,
4663 GLint internalFormat
,
4664 GLint width
, GLint height
, GLint depth
,
4666 GLsizei imageSize
, const GLvoid
*data
,
4667 struct gl_texture_object
*texObj
,
4668 struct gl_texture_image
*texImage
)
4670 /* this space intentionally left blank */
4672 (void) target
; (void) level
;
4673 (void) internalFormat
;
4674 (void) width
; (void) height
; (void) depth
;
4676 (void) imageSize
; (void) data
;
4684 * Fallback for Driver.CompressedTexSubImage1D()
4687 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4689 GLint xoffset
, GLsizei width
,
4691 GLsizei imageSize
, const GLvoid
*data
,
4692 struct gl_texture_object
*texObj
,
4693 struct gl_texture_image
*texImage
)
4695 /* there are no compressed 1D texture formats yet */
4697 (void) target
; (void) level
;
4698 (void) xoffset
; (void) width
;
4700 (void) imageSize
; (void) data
;
4707 * Fallback for Driver.CompressedTexSubImage2D()
4710 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4712 GLint xoffset
, GLint yoffset
,
4713 GLsizei width
, GLsizei height
,
4715 GLsizei imageSize
, const GLvoid
*data
,
4716 struct gl_texture_object
*texObj
,
4717 struct gl_texture_image
*texImage
)
4719 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4723 const gl_format texFormat
= texImage
->TexFormat
;
4724 const GLint destWidth
= texImage
->Width
;
4727 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4732 /* these should have been caught sooner */
4733 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4734 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4735 ASSERT((xoffset
% bw
) == 0);
4736 ASSERT((yoffset
% bh
) == 0);
4738 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4739 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4741 "glCompressedTexSubImage2D");
4745 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4746 src
= (const GLubyte
*) data
;
4748 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4749 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4750 texFormat
, destWidth
,
4751 (GLubyte
*) texImage
->Data
);
4753 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4754 rows
= height
/ bh
; /* rows in blocks */
4756 /* copy rows of blocks */
4757 for (i
= 0; i
< rows
; i
++) {
4758 memcpy(dest
, src
, bytesPerRow
);
4759 dest
+= destRowStride
;
4760 src
+= srcRowStride
;
4763 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4768 * Fallback for Driver.CompressedTexSubImage3D()
4771 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4773 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4774 GLsizei width
, GLsizei height
, GLsizei depth
,
4776 GLsizei imageSize
, const GLvoid
*data
,
4777 struct gl_texture_object
*texObj
,
4778 struct gl_texture_image
*texImage
)
4780 /* there are no compressed 3D texture formats yet */
4782 (void) target
; (void) level
;
4783 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4784 (void) width
; (void) height
; (void) depth
;
4786 (void) imageSize
; (void) data
;