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"
73 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
74 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
84 * Texture image storage function.
86 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
90 * Return GL_TRUE if the given image format is one that be converted
91 * to another format by swizzling.
94 can_swizzle(GLenum logicalBaseFormat
)
96 switch (logicalBaseFormat
) {
99 case GL_LUMINANCE_ALPHA
:
135 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
136 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
137 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
138 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
141 static const struct {
144 GLubyte from_rgba
[6];
145 } mappings
[MAX_IDX
] =
155 MAP4(ZERO
, ZERO
, ZERO
, 0),
185 MAP4(0, ZERO
, ZERO
, ONE
),
191 MAP4(ZERO
, 0, ZERO
, ONE
),
197 MAP4(ZERO
, ZERO
, 0, ONE
),
221 MAP4(0, 1, ZERO
, ONE
),
229 * Convert a GL image format enum to an IDX_* value (see above).
232 get_map_idx(GLenum value
)
235 case GL_LUMINANCE
: return IDX_LUMINANCE
;
236 case GL_ALPHA
: return IDX_ALPHA
;
237 case GL_INTENSITY
: return IDX_INTENSITY
;
238 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
239 case GL_RGB
: return IDX_RGB
;
240 case GL_RGBA
: return IDX_RGBA
;
241 case GL_RED
: return IDX_RED
;
242 case GL_GREEN
: return IDX_GREEN
;
243 case GL_BLUE
: return IDX_BLUE
;
244 case GL_BGR
: return IDX_BGR
;
245 case GL_BGRA
: return IDX_BGRA
;
246 case GL_ABGR_EXT
: return IDX_ABGR
;
247 case GL_RG
: return IDX_RG
;
249 _mesa_problem(NULL
, "Unexpected inFormat");
256 * When promoting texture formats (see below) we need to compute the
257 * mapping of dest components back to source components.
258 * This function does that.
259 * \param inFormat the incoming format of the texture
260 * \param outFormat the final texture format
261 * \return map[6] a full 6-component map
264 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
267 const int inFmt
= get_map_idx(inFormat
);
268 const int outFmt
= get_map_idx(outFormat
);
269 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
270 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
273 for (i
= 0; i
< 4; i
++)
274 map
[i
] = in2rgba
[rgba2out
[i
]];
280 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
281 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
282 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
294 * Make a temporary (color) texture image with GLfloat components.
295 * Apply all needed pixel unpacking and pixel transfer operations.
296 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
297 * Suppose the user specifies GL_LUMINANCE as the internal texture format
298 * but the graphics hardware doesn't support luminance textures. So, we might
299 * use an RGB hardware format instead.
300 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
302 * \param ctx the rendering context
303 * \param dims image dimensions: 1, 2 or 3
304 * \param logicalBaseFormat basic texture derived from the user's
305 * internal texture format value
306 * \param textureBaseFormat the actual basic format of the texture
307 * \param srcWidth source image width
308 * \param srcHeight source image height
309 * \param srcDepth source image depth
310 * \param srcFormat source image format
311 * \param srcType source image type
312 * \param srcAddr source image address
313 * \param srcPacking source image pixel packing
314 * \return resulting image with format = textureBaseFormat and type = GLfloat.
317 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
318 GLenum logicalBaseFormat
,
319 GLenum textureBaseFormat
,
320 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
321 GLenum srcFormat
, GLenum srcType
,
322 const GLvoid
*srcAddr
,
323 const struct gl_pixelstore_attrib
*srcPacking
,
324 GLbitfield transferOps
)
327 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
328 const GLint srcStride
=
329 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
333 ASSERT(dims
>= 1 && dims
<= 3);
335 ASSERT(logicalBaseFormat
== GL_RGBA
||
336 logicalBaseFormat
== GL_RGB
||
337 logicalBaseFormat
== GL_RG
||
338 logicalBaseFormat
== GL_RED
||
339 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
340 logicalBaseFormat
== GL_LUMINANCE
||
341 logicalBaseFormat
== GL_ALPHA
||
342 logicalBaseFormat
== GL_INTENSITY
||
343 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
345 ASSERT(textureBaseFormat
== GL_RGBA
||
346 textureBaseFormat
== GL_RGB
||
347 textureBaseFormat
== GL_RG
||
348 textureBaseFormat
== GL_RED
||
349 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
350 textureBaseFormat
== GL_LUMINANCE
||
351 textureBaseFormat
== GL_ALPHA
||
352 textureBaseFormat
== GL_INTENSITY
||
353 textureBaseFormat
== GL_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 GLubyte 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 = GLubyte.
557 _mesa_make_temp_ubyte_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 GLubyte
*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
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
592 * components
* sizeof(GLubyte
));
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_ubyte(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
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
633 * texComponents
* sizeof(GLubyte
));
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
] = 255;
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 or float depth component texture image.
1006 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1008 const GLuint depthScale
= 0xffffffff;
1009 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1010 const GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
1012 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
1013 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
1014 ASSERT(texelBytes
== sizeof(GLuint
));
1016 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1017 ctx
->Pixel
.DepthBias
== 0.0f
&&
1018 !srcPacking
->SwapBytes
&&
1019 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1020 srcFormat
== GL_DEPTH_COMPONENT
&&
1021 srcType
== dstType
) {
1022 /* simple memcpy path */
1023 memcpy_texture(ctx
, dims
,
1024 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1027 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1028 srcAddr
, srcPacking
);
1033 for (img
= 0; img
< srcDepth
; img
++) {
1034 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1035 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1036 + dstYoffset
* dstRowStride
1037 + dstXoffset
* texelBytes
;
1038 for (row
= 0; row
< srcHeight
; row
++) {
1039 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1040 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1041 _mesa_unpack_depth_span(ctx
, srcWidth
,
1043 depthScale
, srcType
, src
, srcPacking
);
1044 dstRow
+= dstRowStride
;
1053 * Store a 24-bit integer depth component texture image.
1056 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1058 const GLuint depthScale
= 0xffffff;
1059 const GLuint texelBytes
= 4;
1062 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1067 for (img
= 0; img
< srcDepth
; img
++) {
1068 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1069 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1070 + dstYoffset
* dstRowStride
1071 + dstXoffset
* texelBytes
;
1072 for (row
= 0; row
< srcHeight
; row
++) {
1073 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1074 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1075 _mesa_unpack_depth_span(ctx
, srcWidth
,
1076 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1077 depthScale
, srcType
, src
, srcPacking
);
1078 dstRow
+= dstRowStride
;
1087 * Store a 24-bit integer depth component texture image.
1090 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1092 const GLuint depthScale
= 0xffffff;
1093 const GLuint texelBytes
= 4;
1096 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1101 for (img
= 0; img
< srcDepth
; img
++) {
1102 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1103 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1104 + dstYoffset
* dstRowStride
1105 + dstXoffset
* texelBytes
;
1106 for (row
= 0; row
< srcHeight
; row
++) {
1107 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1108 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1109 GLuint
*dst
= (GLuint
*) dstRow
;
1111 _mesa_unpack_depth_span(ctx
, srcWidth
,
1112 GL_UNSIGNED_INT
, dst
,
1113 depthScale
, srcType
, src
, srcPacking
);
1114 for (i
= 0; i
< srcWidth
; i
++)
1116 dstRow
+= dstRowStride
;
1125 * Store a 16-bit integer depth component texture image.
1128 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1130 const GLuint depthScale
= 0xffff;
1131 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1133 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1134 ASSERT(texelBytes
== sizeof(GLushort
));
1136 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1137 ctx
->Pixel
.DepthBias
== 0.0f
&&
1138 !srcPacking
->SwapBytes
&&
1139 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1140 srcFormat
== GL_DEPTH_COMPONENT
&&
1141 srcType
== GL_UNSIGNED_SHORT
) {
1142 /* simple memcpy path */
1143 memcpy_texture(ctx
, dims
,
1144 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1147 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1148 srcAddr
, srcPacking
);
1153 for (img
= 0; img
< srcDepth
; img
++) {
1154 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1155 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1156 + dstYoffset
* dstRowStride
1157 + dstXoffset
* texelBytes
;
1158 for (row
= 0; row
< srcHeight
; row
++) {
1159 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1160 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1161 GLushort
*dst16
= (GLushort
*) dstRow
;
1162 _mesa_unpack_depth_span(ctx
, srcWidth
,
1163 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1164 srcType
, src
, srcPacking
);
1165 dstRow
+= dstRowStride
;
1174 * Store an rgb565 or rgb565_rev texture image.
1177 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1179 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1180 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1182 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1183 dstFormat
== MESA_FORMAT_RGB565_REV
);
1184 ASSERT(texelBytes
== 2);
1186 if (!ctx
->_ImageTransferState
&&
1187 !srcPacking
->SwapBytes
&&
1188 dstFormat
== MESA_FORMAT_RGB565
&&
1189 baseInternalFormat
== GL_RGB
&&
1190 srcFormat
== GL_RGB
&&
1191 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1192 /* simple memcpy path */
1193 memcpy_texture(ctx
, dims
,
1194 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1197 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1198 srcAddr
, srcPacking
);
1200 else if (!ctx
->_ImageTransferState
&&
1201 !srcPacking
->SwapBytes
&&
1202 baseInternalFormat
== GL_RGB
&&
1203 srcFormat
== GL_RGB
&&
1204 srcType
== GL_UNSIGNED_BYTE
&&
1206 /* do optimized tex store */
1207 const GLint srcRowStride
=
1208 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1209 const GLubyte
*src
= (const GLubyte
*)
1210 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1211 srcFormat
, srcType
, 0, 0, 0);
1212 GLubyte
*dst
= (GLubyte
*) dstAddr
1213 + dstYoffset
* dstRowStride
1214 + dstXoffset
* texelBytes
;
1216 for (row
= 0; row
< srcHeight
; row
++) {
1217 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1218 GLushort
*dstUS
= (GLushort
*) dst
;
1219 /* check for byteswapped format */
1220 if (dstFormat
== MESA_FORMAT_RGB565
) {
1221 for (col
= 0; col
< srcWidth
; col
++) {
1222 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1227 for (col
= 0; col
< srcWidth
; col
++) {
1228 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1232 dst
+= dstRowStride
;
1233 src
+= srcRowStride
;
1238 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1241 srcWidth
, srcHeight
, srcDepth
,
1242 srcFormat
, srcType
, srcAddr
,
1244 const GLubyte
*src
= tempImage
;
1245 GLint img
, row
, col
;
1248 for (img
= 0; img
< srcDepth
; img
++) {
1249 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1250 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1251 + dstYoffset
* dstRowStride
1252 + dstXoffset
* texelBytes
;
1253 for (row
= 0; row
< srcHeight
; row
++) {
1254 GLushort
*dstUS
= (GLushort
*) dstRow
;
1255 /* check for byteswapped format */
1256 if (dstFormat
== MESA_FORMAT_RGB565
) {
1257 for (col
= 0; col
< srcWidth
; col
++) {
1258 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1265 for (col
= 0; col
< srcWidth
; col
++) {
1266 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1272 dstRow
+= dstRowStride
;
1275 free((void *) tempImage
);
1282 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1285 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1287 const GLboolean littleEndian
= _mesa_little_endian();
1288 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1289 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1291 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1292 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1293 ASSERT(texelBytes
== 4);
1295 if (!ctx
->_ImageTransferState
&&
1296 !srcPacking
->SwapBytes
&&
1297 dstFormat
== MESA_FORMAT_RGBA8888
&&
1298 baseInternalFormat
== GL_RGBA
&&
1299 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1300 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1301 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1302 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1303 /* simple memcpy path */
1304 memcpy_texture(ctx
, dims
,
1305 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1308 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1309 srcAddr
, srcPacking
);
1311 else if (!ctx
->_ImageTransferState
&&
1312 !srcPacking
->SwapBytes
&&
1313 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1314 baseInternalFormat
== GL_RGBA
&&
1315 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1316 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1317 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1318 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1319 /* simple memcpy path */
1320 memcpy_texture(ctx
, dims
,
1321 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1324 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1325 srcAddr
, srcPacking
);
1327 else if (!ctx
->_ImageTransferState
&&
1328 (srcType
== GL_UNSIGNED_BYTE
||
1329 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1330 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1331 can_swizzle(baseInternalFormat
) &&
1332 can_swizzle(srcFormat
)) {
1336 /* dstmap - how to swizzle from RGBA to dst format:
1338 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1339 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1352 _mesa_swizzle_ubyte_image(ctx
, dims
,
1357 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1358 dstRowStride
, dstImageOffsets
,
1359 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1364 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1367 srcWidth
, srcHeight
, srcDepth
,
1368 srcFormat
, srcType
, srcAddr
,
1370 const GLubyte
*src
= tempImage
;
1371 GLint img
, row
, col
;
1374 for (img
= 0; img
< srcDepth
; img
++) {
1375 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1376 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1377 + dstYoffset
* dstRowStride
1378 + dstXoffset
* texelBytes
;
1379 for (row
= 0; row
< srcHeight
; row
++) {
1380 GLuint
*dstUI
= (GLuint
*) dstRow
;
1381 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1382 for (col
= 0; col
< srcWidth
; col
++) {
1383 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1391 for (col
= 0; col
< srcWidth
; col
++) {
1392 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1399 dstRow
+= dstRowStride
;
1402 free((void *) tempImage
);
1409 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1411 const GLboolean littleEndian
= _mesa_little_endian();
1412 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1413 const GLenum baseFormat
= GL_RGBA
;
1415 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1416 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1417 dstFormat
== MESA_FORMAT_XRGB8888
||
1418 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1419 ASSERT(texelBytes
== 4);
1421 if (!ctx
->_ImageTransferState
&&
1422 !srcPacking
->SwapBytes
&&
1423 (dstFormat
== MESA_FORMAT_ARGB8888
||
1424 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1425 baseInternalFormat
== GL_RGBA
&&
1426 srcFormat
== GL_BGRA
&&
1427 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1428 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1429 /* simple memcpy path (little endian) */
1430 memcpy_texture(ctx
, dims
,
1431 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1434 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1435 srcAddr
, srcPacking
);
1437 else if (!ctx
->_ImageTransferState
&&
1438 !srcPacking
->SwapBytes
&&
1439 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1440 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1441 baseInternalFormat
== GL_RGBA
&&
1442 srcFormat
== GL_BGRA
&&
1443 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1444 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1445 /* simple memcpy path (big endian) */
1446 memcpy_texture(ctx
, dims
,
1447 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1450 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1451 srcAddr
, srcPacking
);
1453 else if (!ctx
->_ImageTransferState
&&
1454 !srcPacking
->SwapBytes
&&
1455 (dstFormat
== MESA_FORMAT_ARGB8888
||
1456 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1457 srcFormat
== GL_RGB
&&
1458 (baseInternalFormat
== GL_RGBA
||
1459 baseInternalFormat
== GL_RGB
) &&
1460 srcType
== GL_UNSIGNED_BYTE
) {
1462 for (img
= 0; img
< srcDepth
; img
++) {
1463 const GLint srcRowStride
=
1464 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1465 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1466 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1467 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1468 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1469 + dstYoffset
* dstRowStride
1470 + dstXoffset
* texelBytes
;
1471 for (row
= 0; row
< srcHeight
; row
++) {
1472 GLuint
*d4
= (GLuint
*) dstRow
;
1473 for (col
= 0; col
< srcWidth
; col
++) {
1474 d4
[col
] = PACK_COLOR_8888(0xff,
1475 srcRow
[col
* 3 + RCOMP
],
1476 srcRow
[col
* 3 + GCOMP
],
1477 srcRow
[col
* 3 + BCOMP
]);
1479 dstRow
+= dstRowStride
;
1480 srcRow
+= srcRowStride
;
1484 else if (!ctx
->_ImageTransferState
&&
1485 !srcPacking
->SwapBytes
&&
1486 dstFormat
== MESA_FORMAT_ARGB8888
&&
1487 srcFormat
== GL_RGBA
&&
1488 baseInternalFormat
== GL_RGBA
&&
1489 srcType
== GL_UNSIGNED_BYTE
) {
1490 /* same as above case, but src data has alpha too */
1491 GLint img
, row
, col
;
1492 /* For some reason, streaming copies to write-combined regions
1493 * are extremely sensitive to the characteristics of how the
1494 * source data is retrieved. By reordering the source reads to
1495 * be in-order, the speed of this operation increases by half.
1496 * Strangely the same isn't required for the RGB path, above.
1498 for (img
= 0; img
< srcDepth
; img
++) {
1499 const GLint srcRowStride
=
1500 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1501 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1502 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1503 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1504 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1505 + dstYoffset
* dstRowStride
1506 + dstXoffset
* texelBytes
;
1507 for (row
= 0; row
< srcHeight
; row
++) {
1508 GLuint
*d4
= (GLuint
*) dstRow
;
1509 for (col
= 0; col
< srcWidth
; col
++) {
1510 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1511 srcRow
[col
* 4 + RCOMP
],
1512 srcRow
[col
* 4 + GCOMP
],
1513 srcRow
[col
* 4 + BCOMP
]);
1515 dstRow
+= dstRowStride
;
1516 srcRow
+= srcRowStride
;
1520 else if (!ctx
->_ImageTransferState
&&
1521 (srcType
== GL_UNSIGNED_BYTE
||
1522 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1523 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1524 can_swizzle(baseInternalFormat
) &&
1525 can_swizzle(srcFormat
)) {
1529 /* dstmap - how to swizzle from RGBA to dst format:
1531 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1532 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1533 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1534 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1535 dstmap
[3] = 3; /* alpha */
1536 dstmap
[2] = 0; /* red */
1537 dstmap
[1] = 1; /* green */
1538 dstmap
[0] = 2; /* blue */
1541 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1542 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1543 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1544 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1551 _mesa_swizzle_ubyte_image(ctx
, dims
,
1556 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1559 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1564 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1567 srcWidth
, srcHeight
, srcDepth
,
1568 srcFormat
, srcType
, srcAddr
,
1570 const GLubyte
*src
= tempImage
;
1571 GLint img
, row
, col
;
1574 for (img
= 0; img
< srcDepth
; img
++) {
1575 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1576 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1577 + dstYoffset
* dstRowStride
1578 + dstXoffset
* texelBytes
;
1579 for (row
= 0; row
< srcHeight
; row
++) {
1580 GLuint
*dstUI
= (GLuint
*) dstRow
;
1581 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1582 for (col
= 0; col
< srcWidth
; col
++) {
1583 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1590 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1591 for (col
= 0; col
< srcWidth
; col
++) {
1592 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1600 for (col
= 0; col
< srcWidth
; col
++) {
1601 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1608 dstRow
+= dstRowStride
;
1611 free((void *) tempImage
);
1618 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1620 const GLboolean littleEndian
= _mesa_little_endian();
1621 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1622 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1624 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1625 ASSERT(texelBytes
== 3);
1627 if (!ctx
->_ImageTransferState
&&
1628 !srcPacking
->SwapBytes
&&
1629 baseInternalFormat
== GL_RGB
&&
1630 srcFormat
== GL_BGR
&&
1631 srcType
== GL_UNSIGNED_BYTE
&&
1633 /* simple memcpy path */
1634 memcpy_texture(ctx
, dims
,
1635 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1638 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1639 srcAddr
, srcPacking
);
1641 else if (!ctx
->_ImageTransferState
&&
1642 !srcPacking
->SwapBytes
&&
1643 srcFormat
== GL_RGBA
&&
1644 srcType
== GL_UNSIGNED_BYTE
) {
1645 /* extract RGB from RGBA */
1646 GLint img
, row
, col
;
1647 for (img
= 0; img
< srcDepth
; img
++) {
1648 const GLint srcRowStride
=
1649 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1650 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1651 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1652 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1653 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1654 + dstYoffset
* dstRowStride
1655 + dstXoffset
* texelBytes
;
1656 for (row
= 0; row
< srcHeight
; row
++) {
1657 for (col
= 0; col
< srcWidth
; col
++) {
1658 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1659 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1660 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1662 dstRow
+= dstRowStride
;
1663 srcRow
+= srcRowStride
;
1667 else if (!ctx
->_ImageTransferState
&&
1668 srcType
== GL_UNSIGNED_BYTE
&&
1669 can_swizzle(baseInternalFormat
) &&
1670 can_swizzle(srcFormat
)) {
1674 /* dstmap - how to swizzle from RGBA to dst format:
1679 dstmap
[3] = ONE
; /* ? */
1681 _mesa_swizzle_ubyte_image(ctx
, dims
,
1686 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1687 dstRowStride
, dstImageOffsets
,
1688 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1693 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1696 srcWidth
, srcHeight
, srcDepth
,
1697 srcFormat
, srcType
, srcAddr
,
1699 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1700 GLint img
, row
, col
;
1703 for (img
= 0; img
< srcDepth
; img
++) {
1704 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1705 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1706 + dstYoffset
* dstRowStride
1707 + dstXoffset
* texelBytes
;
1708 for (row
= 0; row
< srcHeight
; row
++) {
1711 for (col
= 0; col
< srcWidth
; col
++) {
1712 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1713 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1714 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1719 for (col
= 0; col
< srcWidth
; col
++) {
1720 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1721 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1722 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1727 for (col
= 0; col
< srcWidth
; col
++) {
1728 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1729 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1730 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1734 dstRow
+= dstRowStride
;
1737 free((void *) tempImage
);
1744 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1746 const GLboolean littleEndian
= _mesa_little_endian();
1747 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1748 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1750 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1751 ASSERT(texelBytes
== 3);
1753 if (!ctx
->_ImageTransferState
&&
1754 !srcPacking
->SwapBytes
&&
1755 baseInternalFormat
== GL_RGB
&&
1756 srcFormat
== GL_RGB
&&
1757 srcType
== GL_UNSIGNED_BYTE
&&
1759 /* simple memcpy path */
1760 memcpy_texture(ctx
, dims
,
1761 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1764 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1765 srcAddr
, srcPacking
);
1767 else if (!ctx
->_ImageTransferState
&&
1768 !srcPacking
->SwapBytes
&&
1769 srcFormat
== GL_RGBA
&&
1770 srcType
== GL_UNSIGNED_BYTE
) {
1771 /* extract BGR from RGBA */
1773 for (img
= 0; img
< srcDepth
; img
++) {
1774 const GLint srcRowStride
=
1775 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1776 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1777 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1778 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1779 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1780 + dstYoffset
* dstRowStride
1781 + dstXoffset
* texelBytes
;
1782 for (row
= 0; row
< srcHeight
; row
++) {
1783 for (col
= 0; col
< srcWidth
; col
++) {
1784 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1785 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1786 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1788 dstRow
+= dstRowStride
;
1789 srcRow
+= srcRowStride
;
1793 else if (!ctx
->_ImageTransferState
&&
1794 srcType
== GL_UNSIGNED_BYTE
&&
1795 can_swizzle(baseInternalFormat
) &&
1796 can_swizzle(srcFormat
)) {
1800 /* dstmap - how to swizzle from RGBA to dst format:
1805 dstmap
[3] = ONE
; /* ? */
1807 _mesa_swizzle_ubyte_image(ctx
, dims
,
1812 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1813 dstRowStride
, dstImageOffsets
,
1814 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1819 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1822 srcWidth
, srcHeight
, srcDepth
,
1823 srcFormat
, srcType
, srcAddr
,
1825 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1826 GLint img
, row
, col
;
1829 for (img
= 0; img
< srcDepth
; img
++) {
1830 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1831 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1832 + dstYoffset
* dstRowStride
1833 + dstXoffset
* texelBytes
;
1834 for (row
= 0; row
< srcHeight
; row
++) {
1835 for (col
= 0; col
< srcWidth
; col
++) {
1836 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1837 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1838 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1841 dstRow
+= dstRowStride
;
1844 free((void *) tempImage
);
1851 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1853 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1854 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1856 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1857 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1858 ASSERT(texelBytes
== 2);
1860 if (!ctx
->_ImageTransferState
&&
1861 !srcPacking
->SwapBytes
&&
1862 dstFormat
== MESA_FORMAT_ARGB4444
&&
1863 baseInternalFormat
== GL_RGBA
&&
1864 srcFormat
== GL_BGRA
&&
1865 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1866 /* simple memcpy path */
1867 memcpy_texture(ctx
, dims
,
1868 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1871 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1872 srcAddr
, srcPacking
);
1876 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1879 srcWidth
, srcHeight
, srcDepth
,
1880 srcFormat
, srcType
, srcAddr
,
1882 const GLubyte
*src
= tempImage
;
1883 GLint img
, row
, col
;
1886 for (img
= 0; img
< srcDepth
; img
++) {
1887 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1888 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1889 + dstYoffset
* dstRowStride
1890 + dstXoffset
* texelBytes
;
1891 for (row
= 0; row
< srcHeight
; row
++) {
1892 GLushort
*dstUS
= (GLushort
*) dstRow
;
1893 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1894 for (col
= 0; col
< srcWidth
; col
++) {
1895 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1903 for (col
= 0; col
< srcWidth
; col
++) {
1904 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1911 dstRow
+= dstRowStride
;
1914 free((void *) tempImage
);
1920 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1922 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1923 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1925 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1926 ASSERT(texelBytes
== 2);
1928 if (!ctx
->_ImageTransferState
&&
1929 !srcPacking
->SwapBytes
&&
1930 dstFormat
== MESA_FORMAT_RGBA5551
&&
1931 baseInternalFormat
== GL_RGBA
&&
1932 srcFormat
== GL_RGBA
&&
1933 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1934 /* simple memcpy path */
1935 memcpy_texture(ctx
, dims
,
1936 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1939 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1940 srcAddr
, srcPacking
);
1944 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1947 srcWidth
, srcHeight
, srcDepth
,
1948 srcFormat
, srcType
, srcAddr
,
1950 const GLubyte
*src
=tempImage
;
1951 GLint img
, row
, col
;
1954 for (img
= 0; img
< srcDepth
; img
++) {
1955 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1956 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1957 + dstYoffset
* dstRowStride
1958 + dstXoffset
* texelBytes
;
1959 for (row
= 0; row
< srcHeight
; row
++) {
1960 GLushort
*dstUS
= (GLushort
*) dstRow
;
1961 for (col
= 0; col
< srcWidth
; col
++) {
1962 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1968 dstRow
+= dstRowStride
;
1971 free((void *) tempImage
);
1977 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1979 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1980 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1982 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1983 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1984 ASSERT(texelBytes
== 2);
1986 if (!ctx
->_ImageTransferState
&&
1987 !srcPacking
->SwapBytes
&&
1988 dstFormat
== MESA_FORMAT_ARGB1555
&&
1989 baseInternalFormat
== GL_RGBA
&&
1990 srcFormat
== GL_BGRA
&&
1991 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1992 /* simple memcpy path */
1993 memcpy_texture(ctx
, dims
,
1994 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1997 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1998 srcAddr
, srcPacking
);
2002 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2005 srcWidth
, srcHeight
, srcDepth
,
2006 srcFormat
, srcType
, srcAddr
,
2008 const GLubyte
*src
=tempImage
;
2009 GLint img
, row
, col
;
2012 for (img
= 0; img
< srcDepth
; img
++) {
2013 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2014 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2015 + dstYoffset
* dstRowStride
2016 + dstXoffset
* texelBytes
;
2017 for (row
= 0; row
< srcHeight
; row
++) {
2018 GLushort
*dstUS
= (GLushort
*) dstRow
;
2019 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2020 for (col
= 0; col
< srcWidth
; col
++) {
2021 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
2029 for (col
= 0; col
< srcWidth
; col
++) {
2030 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
2037 dstRow
+= dstRowStride
;
2040 free((void *) tempImage
);
2047 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2049 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2050 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2052 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2053 ASSERT(texelBytes
== 4);
2055 if (!ctx
->_ImageTransferState
&&
2056 !srcPacking
->SwapBytes
&&
2057 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2058 srcFormat
== GL_BGRA
&&
2059 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2060 baseInternalFormat
== GL_RGBA
) {
2061 /* simple memcpy path */
2062 memcpy_texture(ctx
, dims
,
2063 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2066 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2067 srcAddr
, srcPacking
);
2071 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2074 srcWidth
, srcHeight
, srcDepth
,
2075 srcFormat
, srcType
, srcAddr
,
2077 ctx
->_ImageTransferState
);
2078 const GLfloat
*src
= tempImage
;
2079 GLint img
, row
, col
;
2082 for (img
= 0; img
< srcDepth
; img
++) {
2083 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2084 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2085 + dstYoffset
* dstRowStride
2086 + dstXoffset
* texelBytes
;
2087 if (baseInternalFormat
== GL_RGBA
) {
2088 for (row
= 0; row
< srcHeight
; row
++) {
2089 GLuint
*dstUI
= (GLuint
*) dstRow
;
2090 for (col
= 0; col
< srcWidth
; col
++) {
2093 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2094 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2095 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2096 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2097 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2100 dstRow
+= dstRowStride
;
2102 } else if (baseInternalFormat
== GL_RGB
) {
2103 for (row
= 0; row
< srcHeight
; row
++) {
2104 GLuint
*dstUI
= (GLuint
*) dstRow
;
2105 for (col
= 0; col
< srcWidth
; col
++) {
2108 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2109 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2110 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2111 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2114 dstRow
+= dstRowStride
;
2120 free((void *) tempImage
);
2127 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2130 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2132 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2133 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2135 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2136 ASSERT(texelBytes
== 1);
2140 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2143 srcWidth
, srcHeight
, srcDepth
,
2144 srcFormat
, srcType
, srcAddr
,
2146 const GLubyte
*src
= tempImage
;
2147 GLint img
, row
, col
;
2150 for (img
= 0; img
< srcDepth
; img
++) {
2151 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2152 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2153 + dstYoffset
* dstRowStride
2154 + dstXoffset
* texelBytes
;
2155 for (row
= 0; row
< srcHeight
; row
++) {
2156 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2157 for (col
= 0; col
< srcWidth
; col
++) {
2158 /* src[0] is luminance, src[1] is alpha */
2159 dstUS
[col
] = PACK_COLOR_44( src
[1],
2163 dstRow
+= dstRowStride
;
2166 free((void *) tempImage
);
2173 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2176 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2178 const GLboolean littleEndian
= _mesa_little_endian();
2179 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2180 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2182 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2183 dstFormat
== MESA_FORMAT_AL88_REV
||
2184 dstFormat
== MESA_FORMAT_RG88
||
2185 dstFormat
== MESA_FORMAT_RG88_REV
);
2186 ASSERT(texelBytes
== 2);
2188 if (!ctx
->_ImageTransferState
&&
2189 !srcPacking
->SwapBytes
&&
2190 ((dstFormat
== MESA_FORMAT_AL88
&&
2191 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2192 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2193 (dstFormat
== MESA_FORMAT_RG88
&&
2194 baseInternalFormat
== srcFormat
)) &&
2195 srcType
== GL_UNSIGNED_BYTE
&&
2197 /* simple memcpy path */
2198 memcpy_texture(ctx
, dims
,
2199 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2202 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2203 srcAddr
, srcPacking
);
2205 else if (!ctx
->_ImageTransferState
&&
2207 srcType
== GL_UNSIGNED_BYTE
&&
2208 can_swizzle(baseInternalFormat
) &&
2209 can_swizzle(srcFormat
)) {
2212 /* dstmap - how to swizzle from RGBA to dst format:
2214 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2215 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2216 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2226 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2227 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2236 dstmap
[2] = ZERO
; /* ? */
2237 dstmap
[3] = ONE
; /* ? */
2239 _mesa_swizzle_ubyte_image(ctx
, dims
,
2244 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2245 dstRowStride
, dstImageOffsets
,
2246 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2251 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2254 srcWidth
, srcHeight
, srcDepth
,
2255 srcFormat
, srcType
, srcAddr
,
2257 const GLubyte
*src
= tempImage
;
2258 GLint img
, row
, col
;
2261 for (img
= 0; img
< srcDepth
; img
++) {
2262 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2263 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2264 + dstYoffset
* dstRowStride
2265 + dstXoffset
* texelBytes
;
2266 for (row
= 0; row
< srcHeight
; row
++) {
2267 GLushort
*dstUS
= (GLushort
*) dstRow
;
2268 if (dstFormat
== MESA_FORMAT_AL88
||
2269 dstFormat
== MESA_FORMAT_RG88
) {
2270 for (col
= 0; col
< srcWidth
; col
++) {
2271 /* src[0] is luminance, src[1] is alpha */
2272 dstUS
[col
] = PACK_COLOR_88( src
[1],
2278 for (col
= 0; col
< srcWidth
; col
++) {
2279 /* src[0] is luminance, src[1] is alpha */
2280 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2285 dstRow
+= dstRowStride
;
2288 free((void *) tempImage
);
2295 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2298 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2300 const GLboolean littleEndian
= _mesa_little_endian();
2301 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2302 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2304 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2305 dstFormat
== MESA_FORMAT_AL1616_REV
||
2306 dstFormat
== MESA_FORMAT_RG1616
||
2307 dstFormat
== MESA_FORMAT_RG1616_REV
);
2308 ASSERT(texelBytes
== 4);
2310 if (!ctx
->_ImageTransferState
&&
2311 !srcPacking
->SwapBytes
&&
2312 ((dstFormat
== MESA_FORMAT_AL1616
&&
2313 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2314 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2315 (dstFormat
== MESA_FORMAT_RG1616
&&
2316 baseInternalFormat
== srcFormat
)) &&
2317 srcType
== GL_UNSIGNED_SHORT
&&
2319 /* simple memcpy path */
2320 memcpy_texture(ctx
, dims
,
2321 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2324 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2325 srcAddr
, srcPacking
);
2329 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2332 srcWidth
, srcHeight
, srcDepth
,
2333 srcFormat
, srcType
, srcAddr
,
2335 ctx
->_ImageTransferState
);
2336 const GLfloat
*src
= tempImage
;
2337 GLint img
, row
, col
;
2340 for (img
= 0; img
< srcDepth
; img
++) {
2341 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2342 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2343 + dstYoffset
* dstRowStride
2344 + dstXoffset
* texelBytes
;
2345 for (row
= 0; row
< srcHeight
; row
++) {
2346 GLuint
*dstUI
= (GLuint
*) dstRow
;
2347 if (dstFormat
== MESA_FORMAT_AL1616
||
2348 dstFormat
== MESA_FORMAT_RG1616
) {
2349 for (col
= 0; col
< srcWidth
; col
++) {
2352 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2353 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2354 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2359 for (col
= 0; col
< srcWidth
; col
++) {
2362 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2363 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2364 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2368 dstRow
+= dstRowStride
;
2371 free((void *) tempImage
);
2377 /* Texstore for R16, A16, L16, I16. */
2379 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2381 const GLboolean littleEndian
= _mesa_little_endian();
2382 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2383 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2385 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2386 dstFormat
== MESA_FORMAT_A16
||
2387 dstFormat
== MESA_FORMAT_L16
||
2388 dstFormat
== MESA_FORMAT_I16
);
2389 ASSERT(texelBytes
== 2);
2391 if (!ctx
->_ImageTransferState
&&
2392 !srcPacking
->SwapBytes
&&
2393 baseInternalFormat
== srcFormat
&&
2394 srcType
== GL_UNSIGNED_SHORT
&&
2396 /* simple memcpy path */
2397 memcpy_texture(ctx
, dims
,
2398 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2401 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2402 srcAddr
, srcPacking
);
2406 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2409 srcWidth
, srcHeight
, srcDepth
,
2410 srcFormat
, srcType
, srcAddr
,
2412 ctx
->_ImageTransferState
);
2413 const GLfloat
*src
= tempImage
;
2414 GLint img
, row
, col
;
2417 for (img
= 0; img
< srcDepth
; img
++) {
2418 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2419 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2420 + dstYoffset
* dstRowStride
2421 + dstXoffset
* texelBytes
;
2422 for (row
= 0; row
< srcHeight
; row
++) {
2423 GLushort
*dstUS
= (GLushort
*) dstRow
;
2424 for (col
= 0; col
< srcWidth
; col
++) {
2427 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2431 dstRow
+= dstRowStride
;
2434 free((void *) tempImage
);
2441 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2443 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2444 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2446 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2447 ASSERT(texelBytes
== 8);
2449 if (!ctx
->_ImageTransferState
&&
2450 !srcPacking
->SwapBytes
&&
2451 baseInternalFormat
== GL_RGBA
&&
2452 srcFormat
== GL_RGBA
&&
2453 srcType
== GL_UNSIGNED_SHORT
) {
2454 /* simple memcpy path */
2455 memcpy_texture(ctx
, dims
,
2456 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2459 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2460 srcAddr
, srcPacking
);
2464 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2467 srcWidth
, srcHeight
, srcDepth
,
2468 srcFormat
, srcType
, srcAddr
,
2470 ctx
->_ImageTransferState
);
2471 const GLfloat
*src
= tempImage
;
2472 GLint img
, row
, col
;
2475 for (img
= 0; img
< srcDepth
; img
++) {
2476 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2477 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2478 + dstYoffset
* dstRowStride
2479 + dstXoffset
* texelBytes
;
2480 for (row
= 0; row
< srcHeight
; row
++) {
2481 GLushort
*dstUS
= (GLushort
*) dstRow
;
2482 for (col
= 0; col
< srcWidth
; col
++) {
2483 GLushort r
, g
, b
, a
;
2485 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2486 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2487 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2488 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2495 dstRow
+= dstRowStride
;
2498 free((void *) tempImage
);
2505 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2507 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2508 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2510 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2511 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2513 if (!ctx
->_ImageTransferState
&&
2514 !srcPacking
->SwapBytes
&&
2515 baseInternalFormat
== GL_RGBA
&&
2516 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2517 srcFormat
== GL_RGBA
&&
2518 srcType
== GL_SHORT
) {
2519 /* simple memcpy path */
2520 memcpy_texture(ctx
, dims
,
2521 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2524 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2525 srcAddr
, srcPacking
);
2529 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2532 srcWidth
, srcHeight
, srcDepth
,
2533 srcFormat
, srcType
, srcAddr
,
2535 ctx
->_ImageTransferState
);
2536 const GLfloat
*src
= tempImage
;
2537 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2538 GLint img
, row
, col
;
2543 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2544 * 3 or 4 components/pixel here.
2546 for (img
= 0; img
< srcDepth
; img
++) {
2547 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2548 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2549 + dstYoffset
* dstRowStride
2550 + dstXoffset
* texelBytes
;
2551 for (row
= 0; row
< srcHeight
; row
++) {
2552 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2553 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2554 for (col
= 0; col
< srcWidth
; col
++) {
2556 for (c
= 0; c
< comps
; c
++) {
2558 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2559 dstRowS
[col
* comps
+ c
] = p
;
2562 dstRow
+= dstRowStride
;
2563 src
+= 4 * srcWidth
;
2565 for (col
= 0; col
< srcWidth
; col
++) {
2567 for (c
= 0; c
< comps
; c
++) {
2569 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2570 dstRowS
[col
* comps
+ c
] = p
;
2573 dstRow
+= dstRowStride
;
2574 src
+= 3 * srcWidth
;
2578 free((void *) tempImage
);
2585 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2587 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2588 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2590 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2591 ASSERT(texelBytes
== 1);
2593 if (!ctx
->_ImageTransferState
&&
2594 !srcPacking
->SwapBytes
&&
2595 baseInternalFormat
== GL_RGB
&&
2596 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2597 /* simple memcpy path */
2598 memcpy_texture(ctx
, dims
,
2599 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2602 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2603 srcAddr
, srcPacking
);
2607 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2610 srcWidth
, srcHeight
, srcDepth
,
2611 srcFormat
, srcType
, srcAddr
,
2613 const GLubyte
*src
= tempImage
;
2614 GLint img
, row
, col
;
2617 for (img
= 0; img
< srcDepth
; img
++) {
2618 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2619 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2620 + dstYoffset
* dstRowStride
2621 + dstXoffset
* texelBytes
;
2622 for (row
= 0; row
< srcHeight
; row
++) {
2623 for (col
= 0; col
< srcWidth
; col
++) {
2624 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2629 dstRow
+= dstRowStride
;
2632 free((void *) tempImage
);
2639 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2642 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2644 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2645 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2647 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2648 dstFormat
== MESA_FORMAT_L8
||
2649 dstFormat
== MESA_FORMAT_I8
||
2650 dstFormat
== MESA_FORMAT_R8
);
2651 ASSERT(texelBytes
== 1);
2653 if (!ctx
->_ImageTransferState
&&
2654 !srcPacking
->SwapBytes
&&
2655 baseInternalFormat
== srcFormat
&&
2656 srcType
== GL_UNSIGNED_BYTE
) {
2657 /* simple memcpy path */
2658 memcpy_texture(ctx
, dims
,
2659 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2662 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2663 srcAddr
, srcPacking
);
2665 else if (!ctx
->_ImageTransferState
&&
2666 srcType
== GL_UNSIGNED_BYTE
&&
2667 can_swizzle(baseInternalFormat
) &&
2668 can_swizzle(srcFormat
)) {
2671 /* dstmap - how to swizzle from RGBA to dst format:
2673 if (dstFormat
== MESA_FORMAT_A8
) {
2679 dstmap
[1] = ZERO
; /* ? */
2680 dstmap
[2] = ZERO
; /* ? */
2681 dstmap
[3] = ONE
; /* ? */
2683 _mesa_swizzle_ubyte_image(ctx
, dims
,
2688 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2689 dstRowStride
, dstImageOffsets
,
2690 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2695 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2698 srcWidth
, srcHeight
, srcDepth
,
2699 srcFormat
, srcType
, srcAddr
,
2701 const GLubyte
*src
= tempImage
;
2702 GLint img
, row
, col
;
2705 for (img
= 0; img
< srcDepth
; img
++) {
2706 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2707 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2708 + dstYoffset
* dstRowStride
2709 + dstXoffset
* texelBytes
;
2710 for (row
= 0; row
< srcHeight
; row
++) {
2711 for (col
= 0; col
< srcWidth
; col
++) {
2712 dstRow
[col
] = src
[col
];
2714 dstRow
+= dstRowStride
;
2718 free((void *) tempImage
);
2726 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2729 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2731 const GLboolean littleEndian
= _mesa_little_endian();
2732 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2734 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2736 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2737 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2738 ASSERT(texelBytes
== 2);
2739 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2740 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2741 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2742 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2743 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2745 /* always just memcpy since no pixel transfer ops apply */
2746 memcpy_texture(ctx
, dims
,
2747 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2750 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2751 srcAddr
, srcPacking
);
2753 /* Check if we need byte swapping */
2754 /* XXX the logic here _might_ be wrong */
2755 if (srcPacking
->SwapBytes
^
2756 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2757 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2760 for (img
= 0; img
< srcDepth
; img
++) {
2761 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2762 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2763 + dstYoffset
* dstRowStride
2764 + dstXoffset
* texelBytes
;
2765 for (row
= 0; row
< srcHeight
; row
++) {
2766 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2767 dstRow
+= dstRowStride
;
2775 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2777 const GLboolean littleEndian
= _mesa_little_endian();
2778 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2780 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2781 ASSERT(texelBytes
== 2);
2782 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2783 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2784 (srcFormat
== GL_DUDV_ATI
));
2785 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2787 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2789 /* simple memcpy path */
2790 memcpy_texture(ctx
, dims
,
2791 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2794 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2795 srcAddr
, srcPacking
);
2797 else if (srcType
== GL_BYTE
) {
2800 /* dstmap - how to swizzle from RGBA to dst format:
2810 dstmap
[2] = ZERO
; /* ? */
2811 dstmap
[3] = ONE
; /* ? */
2813 _mesa_swizzle_ubyte_image(ctx
, dims
,
2814 GL_LUMINANCE_ALPHA
, /* hack */
2815 GL_UNSIGNED_BYTE
, /* hack */
2816 GL_LUMINANCE_ALPHA
, /* hack */
2818 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2819 dstRowStride
, dstImageOffsets
,
2820 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2824 /* general path - note this is defined for 2d textures only */
2825 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2826 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2827 srcFormat
, srcType
);
2828 GLbyte
*tempImage
, *dst
, *src
;
2831 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2832 * components
* sizeof(GLbyte
));
2836 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2837 srcWidth
, srcHeight
,
2842 for (row
= 0; row
< srcHeight
; row
++) {
2843 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2844 dst
, srcFormat
, srcType
, src
,
2846 dst
+= srcWidth
* components
;
2851 dst
= (GLbyte
*) dstAddr
2852 + dstYoffset
* dstRowStride
2853 + dstXoffset
* texelBytes
;
2854 for (row
= 0; row
< srcHeight
; row
++) {
2855 memcpy(dst
, src
, srcWidth
* texelBytes
);
2856 dst
+= dstRowStride
;
2857 src
+= srcWidth
* texelBytes
;
2859 free((void *) tempImage
);
2866 * Store a texture in a signed normalized 8-bit format.
2869 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2871 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2872 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2874 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2875 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2876 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2877 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2878 ASSERT(texelBytes
== 1);
2880 if (!ctx
->_ImageTransferState
&&
2881 !srcPacking
->SwapBytes
&&
2882 baseInternalFormat
== srcFormat
&&
2883 srcType
== GL_BYTE
) {
2884 /* simple memcpy path */
2885 memcpy_texture(ctx
, dims
,
2886 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2889 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2890 srcAddr
, srcPacking
);
2894 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2897 srcWidth
, srcHeight
, srcDepth
,
2898 srcFormat
, srcType
, srcAddr
,
2900 ctx
->_ImageTransferState
);
2901 const GLfloat
*src
= tempImage
;
2902 GLint img
, row
, col
;
2905 for (img
= 0; img
< srcDepth
; img
++) {
2906 GLbyte
*dstRow
= (GLbyte
*) dstAddr
2907 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2908 + dstYoffset
* dstRowStride
2909 + dstXoffset
* texelBytes
;
2910 for (row
= 0; row
< srcHeight
; row
++) {
2911 for (col
= 0; col
< srcWidth
; col
++) {
2912 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2914 dstRow
+= dstRowStride
;
2918 free((void *) tempImage
);
2925 * Store a texture in a signed normalized two-channel 16-bit format.
2928 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2930 const GLboolean littleEndian
= _mesa_little_endian();
2931 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2932 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2934 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2935 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2936 ASSERT(texelBytes
== 2);
2938 if (!ctx
->_ImageTransferState
&&
2939 !srcPacking
->SwapBytes
&&
2940 baseInternalFormat
== srcFormat
&&
2941 srcType
== GL_BYTE
&&
2943 /* simple memcpy path */
2944 memcpy_texture(ctx
, dims
,
2945 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2948 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2949 srcAddr
, srcPacking
);
2953 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2956 srcWidth
, srcHeight
, srcDepth
,
2957 srcFormat
, srcType
, srcAddr
,
2959 ctx
->_ImageTransferState
);
2960 const GLfloat
*src
= tempImage
;
2961 GLint img
, row
, col
;
2964 for (img
= 0; img
< srcDepth
; img
++) {
2965 GLbyte
*dstRow
= (GLbyte
*) dstAddr
2966 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2967 + dstYoffset
* dstRowStride
2968 + dstXoffset
* texelBytes
;
2969 for (row
= 0; row
< srcHeight
; row
++) {
2970 GLbyte
*dst
= dstRow
;
2971 for (col
= 0; col
< srcWidth
; col
++) {
2972 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2973 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2977 dstRow
+= dstRowStride
;
2980 free((void *) tempImage
);
2985 /* Texstore for signed R16, A16, L16, I16. */
2987 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2989 const GLboolean littleEndian
= _mesa_little_endian();
2990 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2991 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2993 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2994 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2995 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2996 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2997 ASSERT(texelBytes
== 2);
2999 if (!ctx
->_ImageTransferState
&&
3000 !srcPacking
->SwapBytes
&&
3001 baseInternalFormat
== srcFormat
&&
3002 srcType
== GL_SHORT
&&
3004 /* simple memcpy path */
3005 memcpy_texture(ctx
, dims
,
3006 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3009 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3010 srcAddr
, srcPacking
);
3014 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3017 srcWidth
, srcHeight
, srcDepth
,
3018 srcFormat
, srcType
, srcAddr
,
3020 ctx
->_ImageTransferState
);
3021 const GLfloat
*src
= tempImage
;
3022 GLint img
, row
, col
;
3025 for (img
= 0; img
< srcDepth
; img
++) {
3026 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3027 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3028 + dstYoffset
* dstRowStride
3029 + dstXoffset
* texelBytes
;
3030 for (row
= 0; row
< srcHeight
; row
++) {
3031 GLshort
*dstUS
= (GLshort
*) dstRow
;
3032 for (col
= 0; col
< srcWidth
; col
++) {
3035 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
3039 dstRow
+= dstRowStride
;
3042 free((void *) tempImage
);
3048 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
3051 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
3053 const GLboolean littleEndian
= _mesa_little_endian();
3054 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3055 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3057 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
3058 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
3059 ASSERT(texelBytes
== 4);
3061 if (!ctx
->_ImageTransferState
&&
3062 !srcPacking
->SwapBytes
&&
3063 baseInternalFormat
== srcFormat
&&
3064 srcType
== GL_SHORT
&&
3066 /* simple memcpy path */
3067 memcpy_texture(ctx
, dims
,
3068 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3071 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3072 srcAddr
, srcPacking
);
3076 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3079 srcWidth
, srcHeight
, srcDepth
,
3080 srcFormat
, srcType
, srcAddr
,
3082 ctx
->_ImageTransferState
);
3083 const GLfloat
*src
= tempImage
;
3084 GLint img
, row
, col
;
3087 for (img
= 0; img
< srcDepth
; img
++) {
3088 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3089 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3090 + dstYoffset
* dstRowStride
3091 + dstXoffset
* texelBytes
;
3092 for (row
= 0; row
< srcHeight
; row
++) {
3093 GLshort
*dst
= (GLshort
*) dstRow
;
3094 for (col
= 0; col
< srcWidth
; col
++) {
3097 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
3098 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
3104 dstRow
+= dstRowStride
;
3107 free((void *) tempImage
);
3113 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
3116 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
3118 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3119 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3121 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
3122 ASSERT(texelBytes
== 4);
3126 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3129 srcWidth
, srcHeight
, srcDepth
,
3130 srcFormat
, srcType
, srcAddr
,
3132 ctx
->_ImageTransferState
);
3133 const GLfloat
*srcRow
= tempImage
;
3134 GLint img
, row
, col
;
3137 for (img
= 0; img
< srcDepth
; img
++) {
3138 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3139 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3140 + dstYoffset
* dstRowStride
3141 + dstXoffset
* texelBytes
;
3142 for (row
= 0; row
< srcHeight
; row
++) {
3143 GLbyte
*dst
= dstRow
;
3144 for (col
= 0; col
< srcWidth
; col
++) {
3145 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3146 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3147 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3152 dstRow
+= dstRowStride
;
3155 free((void *) tempImage
);
3163 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3164 * MESA_FORMAT_SIGNED_RGBA8888_REV
3167 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3169 const GLboolean littleEndian
= _mesa_little_endian();
3170 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3171 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3173 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3174 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3175 ASSERT(texelBytes
== 4);
3177 if (!ctx
->_ImageTransferState
&&
3178 !srcPacking
->SwapBytes
&&
3179 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3180 baseInternalFormat
== GL_RGBA
&&
3181 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3182 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3183 /* simple memcpy path */
3184 memcpy_texture(ctx
, dims
,
3185 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3188 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3189 srcAddr
, srcPacking
);
3191 else if (!ctx
->_ImageTransferState
&&
3192 !srcPacking
->SwapBytes
&&
3193 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3194 baseInternalFormat
== GL_RGBA
&&
3195 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3196 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3197 /* simple memcpy path */
3198 memcpy_texture(ctx
, dims
,
3199 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3202 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3203 srcAddr
, srcPacking
);
3207 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3210 srcWidth
, srcHeight
, srcDepth
,
3211 srcFormat
, srcType
, srcAddr
,
3213 ctx
->_ImageTransferState
);
3214 const GLfloat
*srcRow
= tempImage
;
3215 GLint img
, row
, col
;
3218 for (img
= 0; img
< srcDepth
; img
++) {
3219 GLbyte
*dstRow
= (GLbyte
*) dstAddr
3220 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3221 + dstYoffset
* dstRowStride
3222 + dstXoffset
* texelBytes
;
3223 for (row
= 0; row
< srcHeight
; row
++) {
3224 GLbyte
*dst
= dstRow
;
3225 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3226 for (col
= 0; col
< srcWidth
; col
++) {
3227 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3228 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3229 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3230 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3236 for (col
= 0; col
< srcWidth
; col
++) {
3237 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3238 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3239 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3240 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3245 dstRow
+= dstRowStride
;
3248 free((void *) tempImage
);
3255 * Store a combined depth/stencil texture image.
3258 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3260 const GLuint depthScale
= 0xffffff;
3261 const GLint srcRowStride
3262 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3265 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3266 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3267 srcFormat
== GL_DEPTH_COMPONENT
||
3268 srcFormat
== GL_STENCIL_INDEX
);
3269 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3271 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3272 ctx
->Pixel
.DepthBias
== 0.0f
&&
3273 !srcPacking
->SwapBytes
) {
3275 memcpy_texture(ctx
, dims
,
3276 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3279 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3280 srcAddr
, srcPacking
);
3282 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3283 srcFormat
== GL_STENCIL_INDEX
) {
3284 /* In case we only upload depth we need to preserve the stencil */
3285 for (img
= 0; img
< srcDepth
; img
++) {
3286 GLuint
*dstRow
= (GLuint
*) dstAddr
3287 + dstImageOffsets
[dstZoffset
+ img
]
3288 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3291 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3292 srcWidth
, srcHeight
,
3295 for (row
= 0; row
< srcHeight
; row
++) {
3296 GLuint depth
[MAX_WIDTH
];
3297 GLubyte stencil
[MAX_WIDTH
];
3299 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3301 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3302 keepstencil
= GL_TRUE
;
3304 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3305 keepdepth
= GL_TRUE
;
3308 if (keepdepth
== GL_FALSE
)
3309 /* the 24 depth bits will be in the low position: */
3310 _mesa_unpack_depth_span(ctx
, srcWidth
,
3311 GL_UNSIGNED_INT
, /* dst type */
3312 keepstencil
? depth
: dstRow
, /* dst addr */
3314 srcType
, src
, srcPacking
);
3316 if (keepstencil
== GL_FALSE
)
3317 /* get the 8-bit stencil values */
3318 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3319 GL_UNSIGNED_BYTE
, /* dst type */
3320 stencil
, /* dst addr */
3321 srcType
, src
, srcPacking
,
3322 ctx
->_ImageTransferState
);
3324 for (i
= 0; i
< srcWidth
; i
++) {
3326 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3328 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3331 src
+= srcRowStride
;
3332 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3341 * Store a combined depth/stencil texture image.
3344 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3346 const GLuint depthScale
= 0xffffff;
3347 const GLint srcRowStride
3348 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3351 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3352 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3353 srcFormat
== GL_DEPTH_COMPONENT
||
3354 srcFormat
== GL_STENCIL_INDEX
);
3355 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3356 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3358 for (img
= 0; img
< srcDepth
; img
++) {
3359 GLuint
*dstRow
= (GLuint
*) dstAddr
3360 + dstImageOffsets
[dstZoffset
+ img
]
3361 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3364 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3365 srcWidth
, srcHeight
,
3368 for (row
= 0; row
< srcHeight
; row
++) {
3369 GLuint depth
[MAX_WIDTH
];
3370 GLubyte stencil
[MAX_WIDTH
];
3372 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3374 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3375 keepstencil
= GL_TRUE
;
3377 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3378 keepdepth
= GL_TRUE
;
3381 if (keepdepth
== GL_FALSE
)
3382 /* the 24 depth bits will be in the low position: */
3383 _mesa_unpack_depth_span(ctx
, srcWidth
,
3384 GL_UNSIGNED_INT
, /* dst type */
3385 keepstencil
? depth
: dstRow
, /* dst addr */
3387 srcType
, src
, srcPacking
);
3389 if (keepstencil
== GL_FALSE
)
3390 /* get the 8-bit stencil values */
3391 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3392 GL_UNSIGNED_BYTE
, /* dst type */
3393 stencil
, /* dst addr */
3394 srcType
, src
, srcPacking
,
3395 ctx
->_ImageTransferState
);
3397 /* merge stencil values into depth values */
3398 for (i
= 0; i
< srcWidth
; i
++) {
3400 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3402 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3405 src
+= srcRowStride
;
3406 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3414 * Store simple 8-bit/value stencil texture data.
3417 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3419 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3420 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3422 if (!ctx
->_ImageTransferState
&&
3423 !srcPacking
->SwapBytes
&&
3424 baseInternalFormat
== srcFormat
&&
3425 srcType
== GL_UNSIGNED_BYTE
) {
3426 /* simple memcpy path */
3427 memcpy_texture(ctx
, dims
,
3428 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3431 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3432 srcAddr
, srcPacking
);
3435 const GLint srcRowStride
3436 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3439 for (img
= 0; img
< srcDepth
; img
++) {
3440 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3441 + dstImageOffsets
[dstZoffset
+ img
]
3442 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3445 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3446 srcWidth
, srcHeight
,
3449 for (row
= 0; row
< srcHeight
; row
++) {
3450 GLubyte stencil
[MAX_WIDTH
];
3453 /* get the 8-bit stencil values */
3454 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3455 GL_UNSIGNED_BYTE
, /* dst type */
3456 stencil
, /* dst addr */
3457 srcType
, src
, srcPacking
,
3458 ctx
->_ImageTransferState
);
3459 /* merge stencil values into depth values */
3460 for (i
= 0; i
< srcWidth
; i
++)
3461 dstRow
[i
] = stencil
[i
];
3463 src
+= srcRowStride
;
3464 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3475 * Store an image in any of the formats:
3476 * _mesa_texformat_rgba_float32
3477 * _mesa_texformat_rgb_float32
3478 * _mesa_texformat_alpha_float32
3479 * _mesa_texformat_luminance_float32
3480 * _mesa_texformat_luminance_alpha_float32
3481 * _mesa_texformat_intensity_float32
3484 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3486 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3487 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3488 const GLint components
= _mesa_components_in_format(baseFormat
);
3490 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3491 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3492 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3493 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3494 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3495 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3496 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3497 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3498 ASSERT(baseInternalFormat
== GL_RGBA
||
3499 baseInternalFormat
== GL_RGB
||
3500 baseInternalFormat
== GL_ALPHA
||
3501 baseInternalFormat
== GL_LUMINANCE
||
3502 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3503 baseInternalFormat
== GL_INTENSITY
||
3504 baseInternalFormat
== GL_RED
||
3505 baseInternalFormat
== GL_RG
);
3506 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3508 if (!ctx
->_ImageTransferState
&&
3509 !srcPacking
->SwapBytes
&&
3510 baseInternalFormat
== srcFormat
&&
3511 baseInternalFormat
== baseFormat
&&
3512 srcType
== GL_FLOAT
) {
3513 /* simple memcpy path */
3514 memcpy_texture(ctx
, dims
,
3515 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3518 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3519 srcAddr
, srcPacking
);
3523 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3526 srcWidth
, srcHeight
, srcDepth
,
3527 srcFormat
, srcType
, srcAddr
,
3529 ctx
->_ImageTransferState
);
3530 const GLfloat
*srcRow
= tempImage
;
3535 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3536 for (img
= 0; img
< srcDepth
; img
++) {
3537 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3538 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3539 + dstYoffset
* dstRowStride
3540 + dstXoffset
* texelBytes
;
3541 for (row
= 0; row
< srcHeight
; row
++) {
3542 memcpy(dstRow
, srcRow
, bytesPerRow
);
3543 dstRow
+= dstRowStride
;
3544 srcRow
+= srcWidth
* components
;
3548 free((void *) tempImage
);
3556 * As above, but store 16-bit floats.
3559 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3561 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3562 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3563 const GLint components
= _mesa_components_in_format(baseFormat
);
3565 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3566 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3567 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3568 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3569 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3570 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3571 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3572 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3573 ASSERT(baseInternalFormat
== GL_RGBA
||
3574 baseInternalFormat
== GL_RGB
||
3575 baseInternalFormat
== GL_ALPHA
||
3576 baseInternalFormat
== GL_LUMINANCE
||
3577 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3578 baseInternalFormat
== GL_INTENSITY
||
3579 baseInternalFormat
== GL_RED
||
3580 baseInternalFormat
== GL_RG
);
3581 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3583 if (!ctx
->_ImageTransferState
&&
3584 !srcPacking
->SwapBytes
&&
3585 baseInternalFormat
== srcFormat
&&
3586 baseInternalFormat
== baseFormat
&&
3587 srcType
== GL_HALF_FLOAT_ARB
) {
3588 /* simple memcpy path */
3589 memcpy_texture(ctx
, dims
,
3590 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3593 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3594 srcAddr
, srcPacking
);
3598 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3601 srcWidth
, srcHeight
, srcDepth
,
3602 srcFormat
, srcType
, srcAddr
,
3604 ctx
->_ImageTransferState
);
3605 const GLfloat
*src
= tempImage
;
3609 for (img
= 0; img
< srcDepth
; img
++) {
3610 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3611 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3612 + dstYoffset
* dstRowStride
3613 + dstXoffset
* texelBytes
;
3614 for (row
= 0; row
< srcHeight
; row
++) {
3615 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3617 for (i
= 0; i
< srcWidth
* components
; i
++) {
3618 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3620 dstRow
+= dstRowStride
;
3621 src
+= srcWidth
* components
;
3625 free((void *) tempImage
);
3631 /* non-normalized, signed int8 */
3633 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3635 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3636 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3637 const GLint components
= _mesa_components_in_format(baseFormat
);
3639 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3640 ASSERT(baseInternalFormat
== GL_RGBA
||
3641 baseInternalFormat
== GL_RGB
||
3642 baseInternalFormat
== GL_ALPHA
||
3643 baseInternalFormat
== GL_LUMINANCE
||
3644 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3645 baseInternalFormat
== GL_INTENSITY
);
3646 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3648 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3649 * to integer formats.
3651 if (!srcPacking
->SwapBytes
&&
3652 baseInternalFormat
== srcFormat
&&
3653 srcType
== GL_BYTE
) {
3654 /* simple memcpy path */
3655 memcpy_texture(ctx
, dims
,
3656 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3659 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3660 srcAddr
, srcPacking
);
3664 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3667 srcWidth
, srcHeight
, srcDepth
,
3668 srcFormat
, srcType
, srcAddr
,
3670 const GLfloat
*src
= tempImage
;
3674 for (img
= 0; img
< srcDepth
; img
++) {
3675 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3676 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3677 + dstYoffset
* dstRowStride
3678 + dstXoffset
* texelBytes
;
3679 for (row
= 0; row
< srcHeight
; row
++) {
3680 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3682 for (i
= 0; i
< srcWidth
* components
; i
++) {
3683 dstTexel
[i
] = (GLbyte
) src
[i
];
3685 dstRow
+= dstRowStride
;
3686 src
+= srcWidth
* components
;
3690 free((void *) tempImage
);
3696 /* non-normalized, signed int16 */
3698 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3700 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3701 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3702 const GLint components
= _mesa_components_in_format(baseFormat
);
3704 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3705 ASSERT(baseInternalFormat
== GL_RGBA
||
3706 baseInternalFormat
== GL_RGB
||
3707 baseInternalFormat
== GL_ALPHA
||
3708 baseInternalFormat
== GL_LUMINANCE
||
3709 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3710 baseInternalFormat
== GL_INTENSITY
);
3711 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3713 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3714 * to integer formats.
3716 if (!srcPacking
->SwapBytes
&&
3717 baseInternalFormat
== srcFormat
&&
3718 srcType
== GL_SHORT
) {
3719 /* simple memcpy path */
3720 memcpy_texture(ctx
, dims
,
3721 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3724 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3725 srcAddr
, srcPacking
);
3729 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3732 srcWidth
, srcHeight
, srcDepth
,
3733 srcFormat
, srcType
, srcAddr
,
3735 const GLfloat
*src
= tempImage
;
3739 for (img
= 0; img
< srcDepth
; img
++) {
3740 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3741 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3742 + dstYoffset
* dstRowStride
3743 + dstXoffset
* texelBytes
;
3744 for (row
= 0; row
< srcHeight
; row
++) {
3745 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3747 for (i
= 0; i
< srcWidth
* components
; i
++) {
3748 dstTexel
[i
] = (GLint
) src
[i
];
3750 dstRow
+= dstRowStride
;
3751 src
+= srcWidth
* components
;
3755 free((void *) tempImage
);
3761 /* non-normalized, signed int32 */
3763 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3765 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3766 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3767 const GLint components
= _mesa_components_in_format(baseFormat
);
3769 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3770 ASSERT(baseInternalFormat
== GL_RGBA
||
3771 baseInternalFormat
== GL_RGB
||
3772 baseInternalFormat
== GL_ALPHA
||
3773 baseInternalFormat
== GL_LUMINANCE
||
3774 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3775 baseInternalFormat
== GL_INTENSITY
);
3776 ASSERT(texelBytes
== components
* sizeof(GLint
));
3778 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3779 * to integer formats.
3781 if (!srcPacking
->SwapBytes
&&
3782 baseInternalFormat
== srcFormat
&&
3783 srcType
== GL_INT
) {
3784 /* simple memcpy path */
3785 memcpy_texture(ctx
, dims
,
3786 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3789 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3790 srcAddr
, srcPacking
);
3794 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3797 srcWidth
, srcHeight
, srcDepth
,
3798 srcFormat
, srcType
, srcAddr
,
3800 const GLfloat
*src
= tempImage
;
3804 for (img
= 0; img
< srcDepth
; img
++) {
3805 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3806 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3807 + dstYoffset
* dstRowStride
3808 + dstXoffset
* texelBytes
;
3809 for (row
= 0; row
< srcHeight
; row
++) {
3810 GLint
*dstTexel
= (GLint
*) dstRow
;
3812 for (i
= 0; i
< srcWidth
* components
; i
++) {
3813 dstTexel
[i
] = (GLint
) src
[i
];
3815 dstRow
+= dstRowStride
;
3816 src
+= srcWidth
* components
;
3820 free((void *) tempImage
);
3826 /* non-normalized, unsigned int8 */
3828 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3830 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3831 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3832 const GLint components
= _mesa_components_in_format(baseFormat
);
3834 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3835 ASSERT(baseInternalFormat
== GL_RGBA
||
3836 baseInternalFormat
== GL_RGB
||
3837 baseInternalFormat
== GL_ALPHA
||
3838 baseInternalFormat
== GL_LUMINANCE
||
3839 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3840 baseInternalFormat
== GL_INTENSITY
);
3841 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3843 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3844 * to integer formats.
3846 if (!srcPacking
->SwapBytes
&&
3847 baseInternalFormat
== srcFormat
&&
3848 srcType
== GL_UNSIGNED_BYTE
) {
3849 /* simple memcpy path */
3850 memcpy_texture(ctx
, dims
,
3851 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3854 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3855 srcAddr
, srcPacking
);
3859 const GLuint
*tempImage
=
3860 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3861 srcWidth
, srcHeight
, srcDepth
,
3862 srcFormat
, srcType
, srcAddr
, srcPacking
);
3863 const GLuint
*src
= tempImage
;
3867 for (img
= 0; img
< srcDepth
; img
++) {
3868 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3869 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3870 + dstYoffset
* dstRowStride
3871 + dstXoffset
* texelBytes
;
3872 for (row
= 0; row
< srcHeight
; row
++) {
3873 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3875 for (i
= 0; i
< srcWidth
* components
; i
++) {
3876 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3878 dstRow
+= dstRowStride
;
3879 src
+= srcWidth
* components
;
3883 free((void *) tempImage
);
3889 /* non-normalized, unsigned int16 */
3891 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3893 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3894 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3895 const GLint components
= _mesa_components_in_format(baseFormat
);
3897 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3898 ASSERT(baseInternalFormat
== GL_RGBA
||
3899 baseInternalFormat
== GL_RGB
||
3900 baseInternalFormat
== GL_ALPHA
||
3901 baseInternalFormat
== GL_LUMINANCE
||
3902 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3903 baseInternalFormat
== GL_INTENSITY
);
3904 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3906 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3907 * to integer formats.
3909 if (!srcPacking
->SwapBytes
&&
3910 baseInternalFormat
== srcFormat
&&
3911 srcType
== GL_UNSIGNED_SHORT
) {
3912 /* simple memcpy path */
3913 memcpy_texture(ctx
, dims
,
3914 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3917 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3918 srcAddr
, srcPacking
);
3922 const GLuint
*tempImage
=
3923 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3924 srcWidth
, srcHeight
, srcDepth
,
3925 srcFormat
, srcType
, srcAddr
, srcPacking
);
3926 const GLuint
*src
= tempImage
;
3930 for (img
= 0; img
< srcDepth
; img
++) {
3931 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3932 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3933 + dstYoffset
* dstRowStride
3934 + dstXoffset
* texelBytes
;
3935 for (row
= 0; row
< srcHeight
; row
++) {
3936 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3938 for (i
= 0; i
< srcWidth
* components
; i
++) {
3939 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3941 dstRow
+= dstRowStride
;
3942 src
+= srcWidth
* components
;
3946 free((void *) tempImage
);
3952 /* non-normalized, unsigned int32 */
3954 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3956 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3957 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3958 const GLint components
= _mesa_components_in_format(baseFormat
);
3960 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3961 ASSERT(baseInternalFormat
== GL_RGBA
||
3962 baseInternalFormat
== GL_RGB
||
3963 baseInternalFormat
== GL_ALPHA
||
3964 baseInternalFormat
== GL_LUMINANCE
||
3965 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3966 baseInternalFormat
== GL_INTENSITY
);
3967 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3969 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3970 * to integer formats.
3972 if (!srcPacking
->SwapBytes
&&
3973 baseInternalFormat
== srcFormat
&&
3974 srcType
== GL_UNSIGNED_INT
) {
3975 /* simple memcpy path */
3976 memcpy_texture(ctx
, dims
,
3977 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3980 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3981 srcAddr
, srcPacking
);
3985 const GLuint
*tempImage
=
3986 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3987 srcWidth
, srcHeight
, srcDepth
,
3988 srcFormat
, srcType
, srcAddr
, srcPacking
);
3989 const GLuint
*src
= tempImage
;
3993 for (img
= 0; img
< srcDepth
; img
++) {
3994 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3995 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3996 + dstYoffset
* dstRowStride
3997 + dstXoffset
* texelBytes
;
3998 for (row
= 0; row
< srcHeight
; row
++) {
3999 GLuint
*dstTexel
= (GLuint
*) dstRow
;
4001 for (i
= 0; i
< srcWidth
* components
; i
++) {
4002 dstTexel
[i
] = src
[i
];
4004 dstRow
+= dstRowStride
;
4005 src
+= srcWidth
* components
;
4009 free((void *) tempImage
);
4017 #if FEATURE_EXT_texture_sRGB
4019 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
4021 gl_format newDstFormat
;
4024 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
4026 /* reuse normal rgb texstore code */
4027 newDstFormat
= MESA_FORMAT_RGB888
;
4029 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
4030 newDstFormat
, dstAddr
,
4031 dstXoffset
, dstYoffset
, dstZoffset
,
4032 dstRowStride
, dstImageOffsets
,
4033 srcWidth
, srcHeight
, srcDepth
,
4035 srcAddr
, srcPacking
);
4041 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
4043 gl_format newDstFormat
;
4046 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
4048 /* reuse normal rgba texstore code */
4049 newDstFormat
= MESA_FORMAT_RGBA8888
;
4050 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
4051 newDstFormat
, dstAddr
,
4052 dstXoffset
, dstYoffset
, dstZoffset
,
4053 dstRowStride
, dstImageOffsets
,
4054 srcWidth
, srcHeight
, srcDepth
,
4056 srcAddr
, srcPacking
);
4062 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
4064 gl_format newDstFormat
;
4067 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
4069 /* reuse normal rgba texstore code */
4070 newDstFormat
= MESA_FORMAT_ARGB8888
;
4072 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
4073 newDstFormat
, dstAddr
,
4074 dstXoffset
, dstYoffset
, dstZoffset
,
4075 dstRowStride
, dstImageOffsets
,
4076 srcWidth
, srcHeight
, srcDepth
,
4078 srcAddr
, srcPacking
);
4084 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
4086 gl_format newDstFormat
;
4089 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
4091 newDstFormat
= MESA_FORMAT_L8
;
4093 /* _mesa_textore_a8 handles luminance8 too */
4094 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
4095 newDstFormat
, dstAddr
,
4096 dstXoffset
, dstYoffset
, dstZoffset
,
4097 dstRowStride
, dstImageOffsets
,
4098 srcWidth
, srcHeight
, srcDepth
,
4100 srcAddr
, srcPacking
);
4106 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
4108 gl_format newDstFormat
;
4111 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4113 /* reuse normal luminance/alpha texstore code */
4114 newDstFormat
= MESA_FORMAT_AL88
;
4116 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4117 newDstFormat
, dstAddr
,
4118 dstXoffset
, dstYoffset
, dstZoffset
,
4119 dstRowStride
, dstImageOffsets
,
4120 srcWidth
, srcHeight
, srcDepth
,
4122 srcAddr
, srcPacking
);
4128 /* these are used only in texstore_funcs[] below */
4129 #define _mesa_texstore_srgb8 NULL
4130 #define _mesa_texstore_srgba8 NULL
4131 #define _mesa_texstore_sargb8 NULL
4132 #define _mesa_texstore_sl8 NULL
4133 #define _mesa_texstore_sla8 NULL
4135 #endif /* FEATURE_EXT_texture_sRGB */
4138 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
4140 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4142 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
4143 ASSERT(baseInternalFormat
== GL_RGB
);
4145 if (!ctx
->_ImageTransferState
&&
4146 !srcPacking
->SwapBytes
&&
4147 srcFormat
== GL_RGB
&&
4148 srcType
== GL_UNSIGNED_INT_5_9_9_9_REV
) {
4149 /* simple memcpy path */
4150 memcpy_texture(ctx
, dims
,
4151 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4154 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4155 srcAddr
, srcPacking
);
4159 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4162 srcWidth
, srcHeight
, srcDepth
,
4163 srcFormat
, srcType
, srcAddr
,
4165 ctx
->_ImageTransferState
);
4166 const GLfloat
*srcRow
= tempImage
;
4167 GLint img
, row
, col
;
4170 for (img
= 0; img
< srcDepth
; img
++) {
4171 GLubyte
*dstRow
= (GLubyte
*) dstAddr
4172 + dstImageOffsets
[dstZoffset
+ img
] * 4
4173 + dstYoffset
* dstRowStride
4175 for (row
= 0; row
< srcHeight
; row
++) {
4176 GLuint
*dstUI
= (GLuint
*)dstRow
;
4177 for (col
= 0; col
< srcWidth
; col
++) {
4178 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
4180 dstRow
+= dstRowStride
;
4181 srcRow
+= srcWidth
* 3;
4185 free((void *) tempImage
);
4191 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
4193 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4195 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
4196 ASSERT(baseInternalFormat
== GL_RGB
);
4198 if (!ctx
->_ImageTransferState
&&
4199 !srcPacking
->SwapBytes
&&
4200 srcFormat
== GL_RGB
&&
4201 srcType
== GL_UNSIGNED_INT_10F_11F_11F_REV
) {
4202 /* simple memcpy path */
4203 memcpy_texture(ctx
, dims
,
4204 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4207 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4208 srcAddr
, srcPacking
);
4212 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4215 srcWidth
, srcHeight
, srcDepth
,
4216 srcFormat
, srcType
, srcAddr
,
4218 ctx
->_ImageTransferState
);
4219 const GLfloat
*srcRow
= tempImage
;
4220 GLint img
, row
, col
;
4223 for (img
= 0; img
< srcDepth
; img
++) {
4224 GLubyte
*dstRow
= (GLubyte
*) dstAddr
4225 + dstImageOffsets
[dstZoffset
+ img
] * 4
4226 + dstYoffset
* dstRowStride
4228 for (row
= 0; row
< srcHeight
; row
++) {
4229 GLuint
*dstUI
= (GLuint
*)dstRow
;
4230 for (col
= 0; col
< srcWidth
; col
++) {
4231 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
4233 dstRow
+= dstRowStride
;
4234 srcRow
+= srcWidth
* 3;
4238 free((void *) tempImage
);
4245 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
4247 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
4248 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
4249 srcFormat
== GL_DEPTH_COMPONENT
||
4250 srcFormat
== GL_STENCIL_INDEX
);
4251 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
4252 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
4254 if (srcFormat
== GL_DEPTH_STENCIL
&&
4255 ctx
->Pixel
.DepthScale
== 1.0f
&&
4256 ctx
->Pixel
.DepthBias
== 0.0f
&&
4257 !srcPacking
->SwapBytes
) {
4259 memcpy_texture(ctx
, dims
,
4260 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4263 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4264 srcAddr
, srcPacking
);
4266 else if (srcFormat
== GL_DEPTH_COMPONENT
||
4267 srcFormat
== GL_STENCIL_INDEX
) {
4269 const GLint srcRowStride
4270 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
4273 /* In case we only upload depth we need to preserve the stencil */
4274 for (img
= 0; img
< srcDepth
; img
++) {
4275 uint64_t *dstRow
= (uint64_t *) dstAddr
4276 + dstImageOffsets
[dstZoffset
+ img
]
4277 + dstYoffset
* dstRowStride
/ sizeof(uint64_t)
4280 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
4281 srcWidth
, srcHeight
,
4284 for (row
= 0; row
< srcHeight
; row
++) {
4285 /* The unpack functions with:
4286 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4287 * only write their own dword, so the other dword (stencil
4288 * or depth) is preserved. */
4289 if (srcFormat
!= GL_STENCIL_INDEX
)
4290 _mesa_unpack_depth_span(ctx
, srcWidth
,
4291 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4292 dstRow
, /* dst addr */
4293 1.0f
, srcType
, src
, srcPacking
);
4295 if (srcFormat
!= GL_DEPTH_COMPONENT
)
4296 _mesa_unpack_stencil_span(ctx
, srcWidth
,
4297 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4298 dstRow
, /* dst addr */
4299 srcType
, src
, srcPacking
,
4300 ctx
->_ImageTransferState
);
4302 src
+= srcRowStride
;
4303 dstRow
+= dstRowStride
/ sizeof(uint64_t);
4312 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4313 * XXX this is somewhat temporary.
4315 static const struct {
4317 StoreTexImageFunc Store
;
4319 texstore_funcs
[MESA_FORMAT_COUNT
] =
4321 { MESA_FORMAT_NONE
, NULL
},
4322 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
4323 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
4324 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
4325 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
4326 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
4327 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
4328 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
4329 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
4330 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
4331 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
4332 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
4333 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
4334 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
4335 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
4336 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
4337 { MESA_FORMAT_AL44
, _mesa_texstore_unorm44
},
4338 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
4339 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
4340 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
4341 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
4342 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
4343 { MESA_FORMAT_A8
, _mesa_texstore_unorm8
},
4344 { MESA_FORMAT_A16
, _mesa_texstore_unorm16
},
4345 { MESA_FORMAT_L8
, _mesa_texstore_unorm8
},
4346 { MESA_FORMAT_L16
, _mesa_texstore_unorm16
},
4347 { MESA_FORMAT_I8
, _mesa_texstore_unorm8
},
4348 { MESA_FORMAT_I16
, _mesa_texstore_unorm16
},
4349 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
4350 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
4351 { MESA_FORMAT_R8
, _mesa_texstore_unorm8
},
4352 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
4353 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
4354 { MESA_FORMAT_R16
, _mesa_texstore_unorm16
},
4355 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
4356 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
4357 { MESA_FORMAT_ARGB2101010
, _mesa_texstore_argb2101010
},
4358 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
4359 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
4360 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
4361 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
4362 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
4363 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
4364 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
4365 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
4366 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
4367 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
4368 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
4369 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
4370 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4371 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4372 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4373 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4374 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
4375 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
4376 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4377 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4378 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4379 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4380 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
4381 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
4382 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
4383 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
4384 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4385 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4386 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
4387 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
4388 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4389 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4390 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
4391 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
4392 { MESA_FORMAT_R_FLOAT32
, _mesa_texstore_rgba_float32
},
4393 { MESA_FORMAT_R_FLOAT16
, _mesa_texstore_rgba_float16
},
4394 { MESA_FORMAT_RG_FLOAT32
, _mesa_texstore_rgba_float32
},
4395 { MESA_FORMAT_RG_FLOAT16
, _mesa_texstore_rgba_float16
},
4397 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
4398 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
4399 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
4400 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
4401 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
4402 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
4404 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
4406 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_snorm8
},
4407 { MESA_FORMAT_SIGNED_RG88_REV
, _mesa_texstore_snorm88
},
4408 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
4410 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
4411 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
4413 { MESA_FORMAT_SIGNED_R16
, _mesa_texstore_snorm16
},
4414 { MESA_FORMAT_SIGNED_GR1616
, _mesa_texstore_snorm1616
},
4415 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
4416 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
4417 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
},
4419 { MESA_FORMAT_RED_RGTC1
, _mesa_texstore_red_rgtc1
},
4420 { MESA_FORMAT_SIGNED_RED_RGTC1
, _mesa_texstore_signed_red_rgtc1
},
4421 { MESA_FORMAT_RG_RGTC2
, _mesa_texstore_rg_rgtc2
},
4422 { MESA_FORMAT_SIGNED_RG_RGTC2
, _mesa_texstore_signed_rg_rgtc2
},
4424 /* Re-use the R/RG texstore functions.
4425 * The code is generic enough to handle LATC too. */
4426 { MESA_FORMAT_L_LATC1
, _mesa_texstore_red_rgtc1
},
4427 { MESA_FORMAT_SIGNED_L_LATC1
, _mesa_texstore_signed_red_rgtc1
},
4428 { MESA_FORMAT_LA_LATC2
, _mesa_texstore_rg_rgtc2
},
4429 { MESA_FORMAT_SIGNED_LA_LATC2
, _mesa_texstore_signed_rg_rgtc2
},
4431 { MESA_FORMAT_SIGNED_A8
, _mesa_texstore_snorm8
},
4432 { MESA_FORMAT_SIGNED_L8
, _mesa_texstore_snorm8
},
4433 { MESA_FORMAT_SIGNED_AL88
, _mesa_texstore_snorm88
},
4434 { MESA_FORMAT_SIGNED_I8
, _mesa_texstore_snorm8
},
4436 { MESA_FORMAT_SIGNED_A16
, _mesa_texstore_snorm16
},
4437 { MESA_FORMAT_SIGNED_L16
, _mesa_texstore_snorm16
},
4438 { MESA_FORMAT_SIGNED_AL1616
, _mesa_texstore_snorm1616
},
4439 { MESA_FORMAT_SIGNED_I16
, _mesa_texstore_snorm16
},
4441 { MESA_FORMAT_RGB9_E5_FLOAT
, _mesa_texstore_rgb9_e5
},
4442 { MESA_FORMAT_R11_G11_B10_FLOAT
, _mesa_texstore_r11_g11_b10f
},
4444 { MESA_FORMAT_Z32_FLOAT
, _mesa_texstore_z32
},
4445 { MESA_FORMAT_Z32_FLOAT_X24S8
, _mesa_texstore_z32f_x24s8
},
4450 _mesa_texstore_null(TEXSTORE_PARAMS
)
4452 (void) ctx
; (void) dims
;
4453 (void) baseInternalFormat
;
4456 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4457 (void) dstRowStride
; (void) dstImageOffsets
;
4458 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4459 (void) srcFormat
; (void) srcType
;
4463 /* should never happen */
4464 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4470 * Return the StoreTexImageFunc pointer to store an image in the given format.
4472 static StoreTexImageFunc
4473 _mesa_get_texstore_func(gl_format format
)
4477 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4478 ASSERT(texstore_funcs
[i
].Name
== i
);
4481 ASSERT(texstore_funcs
[format
].Name
== format
);
4483 if (texstore_funcs
[format
].Store
)
4484 return texstore_funcs
[format
].Store
;
4486 return _mesa_texstore_null
;
4491 * Store user data into texture memory.
4492 * Called via glTex[Sub]Image1/2/3D()
4495 _mesa_texstore(TEXSTORE_PARAMS
)
4497 StoreTexImageFunc storeImage
;
4500 storeImage
= _mesa_get_texstore_func(dstFormat
);
4502 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4503 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4504 dstRowStride
, dstImageOffsets
,
4505 srcWidth
, srcHeight
, srcDepth
,
4506 srcFormat
, srcType
, srcAddr
, srcPacking
);
4512 * Normally, we'll only _write_ texel data to a texture when we map it.
4513 * But if the user is providing depth or stencil values and the texture
4514 * image is a combined depth/stencil format, we'll actually read from
4515 * the texture buffer too (in order to insert the depth or stencil values.
4516 * \param userFormat the user-provided image format
4517 * \param texFormat the destination texture format
4520 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4522 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4523 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4524 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4526 return GL_MAP_WRITE_BIT
;
4530 * This is the software fallback for Driver.TexImage1D().
4531 * \sa _mesa_store_teximage2d()
4534 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4535 GLint internalFormat
,
4536 GLint width
, GLint border
,
4537 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4538 const struct gl_pixelstore_attrib
*packing
,
4539 struct gl_texture_object
*texObj
,
4540 struct gl_texture_image
*texImage
)
4542 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4543 const GLuint zeroImageOffset
= 0;
4550 /* allocate storage for texture data */
4551 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4557 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4558 pixels
, packing
, "glTexImage1D");
4560 /* Note: we check for a NULL image pointer here, _after_ we allocated
4561 * memory for the texture. That's what the GL spec calls for.
4566 /* Map dest texture buffer (write to whole region) */
4567 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4570 &dstMap
, &dstRowStride
);
4572 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4573 texImage
->TexFormat
,
4575 0, 0, 0, /* dstX/Y/Zoffset */
4576 0, /* dstRowStride */
4579 format
, type
, pixels
, packing
);
4581 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4584 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4586 _mesa_unmap_teximage_pbo(ctx
, packing
);
4591 * This is the software fallback for Driver.TexImage2D().
4593 * This function is oriented toward storing images in main memory, rather
4594 * than VRAM. Device driver's can easily plug in their own replacement.
4597 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4598 GLint internalFormat
,
4599 GLint width
, GLint height
, GLint border
,
4600 GLenum format
, GLenum type
, const void *pixels
,
4601 const struct gl_pixelstore_attrib
*packing
,
4602 struct gl_texture_object
*texObj
,
4603 struct gl_texture_image
*texImage
)
4605 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4606 const GLuint zeroImageOffset
= 0;
4613 /* allocate storage for texture data */
4614 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4615 width
, height
, 1)) {
4616 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4620 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4621 pixels
, packing
, "glTexImage2D");
4623 /* Note: we check for a NULL image pointer here, _after_ we allocated
4624 * memory for the texture. That's what the GL spec calls for.
4629 /* Map dest texture buffer (write to whole region) */
4630 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4631 0, 0, width
, height
,
4633 &dstMap
, &dstRowStride
);
4635 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4636 texImage
->TexFormat
,
4638 0, 0, 0, /* dstX/Y/Zoffset */
4642 format
, type
, pixels
, packing
);
4644 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4647 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4649 _mesa_unmap_teximage_pbo(ctx
, packing
);
4655 * This is the software fallback for Driver.TexImage3D().
4656 * \sa _mesa_store_teximage2d()
4659 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4660 GLint internalFormat
,
4661 GLint width
, GLint height
, GLint depth
, GLint border
,
4662 GLenum format
, GLenum type
, const void *pixels
,
4663 const struct gl_pixelstore_attrib
*packing
,
4664 struct gl_texture_object
*texObj
,
4665 struct gl_texture_image
*texImage
)
4667 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4670 GLubyte
**sliceMaps
;
4671 GLuint
*dstImageOffsets
;
4673 GLuint texelSize
= _mesa_get_format_bytes(texImage
->TexFormat
);
4677 /* allocate storage for texture data */
4678 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4679 width
, height
, depth
)) {
4680 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4684 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
,
4686 pixels
, packing
, "glTexImage3D");
4688 /* Note: we check for a NULL image pointer here, _after_ we allocated
4689 * memory for the texture. That's what the GL spec calls for.
4694 sliceMaps
= (GLubyte
**) malloc(depth
* sizeof(GLubyte
*));
4695 dstImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
4697 /* Map dest texture buffer slices */
4698 for (slice
= 0; slice
< depth
; slice
++) {
4699 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
,
4700 0, 0, width
, height
,
4702 &sliceMaps
[slice
], &dstRowStride
);
4704 /* Compute image slice offsets */
4705 for (slice
= 0; slice
< depth
; slice
++) {
4706 dstImageOffsets
[slice
] = (sliceMaps
[slice
] - sliceMaps
[0]) / texelSize
;
4709 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4710 texImage
->TexFormat
,
4712 0, 0, 0, /* dstX/Y/Zoffset */
4715 width
, height
, depth
,
4716 format
, type
, pixels
, packing
);
4718 /* Unmap dest texture buffer slices */
4719 for (slice
= 0; slice
< depth
; slice
++) {
4720 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
);
4724 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4726 _mesa_unmap_teximage_pbo(ctx
, packing
);
4729 free(dstImageOffsets
);
4736 * This is the software fallback for Driver.TexSubImage1D()
4737 * and Driver.CopyTexSubImage1D().
4740 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4741 GLint xoffset
, GLint width
,
4742 GLenum format
, GLenum type
, const void *pixels
,
4743 const struct gl_pixelstore_attrib
*packing
,
4744 struct gl_texture_object
*texObj
,
4745 struct gl_texture_image
*texImage
)
4747 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4748 const GLuint zeroImageOffset
= 0;
4753 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4754 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4755 pixels
, packing
, "glTexSubImage1D");
4759 /* Map dest texture buffer (write to whole region) */
4760 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4761 xoffset
, 0, width
, 1,
4763 &dstMap
, &dstRowStride
);
4765 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4766 texImage
->TexFormat
,
4768 0, 0, 0, /* dstX/Y/Zoffset */
4772 format
, type
, pixels
, packing
);
4774 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4777 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4779 _mesa_unmap_teximage_pbo(ctx
, packing
);
4785 * This is the software fallback for Driver.TexSubImage2D()
4786 * and Driver.CopyTexSubImage2D().
4789 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4790 GLint xoffset
, GLint yoffset
,
4791 GLint width
, GLint height
,
4792 GLenum format
, GLenum type
, const void *pixels
,
4793 const struct gl_pixelstore_attrib
*packing
,
4794 struct gl_texture_object
*texObj
,
4795 struct gl_texture_image
*texImage
)
4797 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4798 const GLuint zeroImageOffset
= 0;
4803 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4804 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4805 pixels
, packing
, "glTexSubImage2D");
4809 /* Map dest texture buffer (write to whole region) */
4810 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4811 xoffset
, yoffset
, width
, height
,
4813 &dstMap
, &dstRowStride
);
4815 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4816 texImage
->TexFormat
,
4818 0, 0, 0, /* dstX/Y/Zoffset */
4822 format
, type
, pixels
, packing
);
4824 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4827 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4829 _mesa_unmap_teximage_pbo(ctx
, packing
);
4834 * This is the software fallback for Driver.TexSubImage3D().
4835 * and Driver.CopyTexSubImage3D().
4838 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4839 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4840 GLint width
, GLint height
, GLint depth
,
4841 GLenum format
, GLenum type
, const void *pixels
,
4842 const struct gl_pixelstore_attrib
*packing
,
4843 struct gl_texture_object
*texObj
,
4844 struct gl_texture_image
*texImage
)
4846 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4849 GLubyte
**sliceMaps
;
4850 GLuint
*dstImageOffsets
;
4852 GLuint texelSize
= _mesa_get_format_bytes(texImage
->TexFormat
);
4854 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4855 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4856 type
, pixels
, packing
,
4861 sliceMaps
= (GLubyte
**) malloc((zoffset
+ depth
) * sizeof(GLubyte
*));
4862 dstImageOffsets
= (GLuint
*) malloc((zoffset
+ depth
) * sizeof(GLuint
));
4864 /* Map dest texture buffer slices */
4865 for (slice
= 0; slice
< depth
; slice
++) {
4866 ctx
->Driver
.MapTextureImage(ctx
, texImage
, zoffset
+ slice
,
4867 xoffset
, yoffset
, width
, height
,
4869 &sliceMaps
[zoffset
+ slice
], &dstRowStride
);
4872 /* Compute image slice offsets */
4873 for (slice
= 0; slice
< depth
; slice
++) {
4874 dstImageOffsets
[slice
] =
4875 (sliceMaps
[zoffset
+ slice
] - sliceMaps
[zoffset
]) / texelSize
;
4878 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4879 texImage
->TexFormat
,
4881 0, 0, 0, /* dstX/Y/Zoffset */
4884 width
, height
, depth
,
4885 format
, type
, pixels
, packing
);
4887 /* Unmap dest texture buffer slices */
4888 for (slice
= 0; slice
< depth
; slice
++) {
4889 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, zoffset
+ slice
);
4893 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4895 _mesa_unmap_teximage_pbo(ctx
, packing
);
4898 free(dstImageOffsets
);
4903 * Fallback for Driver.CompressedTexImage1D()
4906 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4907 GLenum target
, GLint level
,
4908 GLint internalFormat
,
4909 GLint width
, GLint border
,
4910 GLsizei imageSize
, const GLvoid
*data
,
4911 struct gl_texture_object
*texObj
,
4912 struct gl_texture_image
*texImage
)
4914 /* this space intentionally left blank */
4916 (void) target
; (void) level
;
4917 (void) internalFormat
;
4918 (void) width
; (void) border
;
4919 (void) imageSize
; (void) data
;
4927 * Fallback for Driver.CompressedTexImage2D()
4930 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4931 GLenum target
, GLint level
,
4932 GLint internalFormat
,
4933 GLint width
, GLint height
, GLint border
,
4934 GLsizei imageSize
, const GLvoid
*data
,
4935 struct gl_texture_object
*texObj
,
4936 struct gl_texture_image
*texImage
)
4941 /* This is pretty simple, basically just do a memcpy without worrying
4942 * about the usual image unpacking or image transfer operations.
4946 ASSERT(texImage
->Width
> 0);
4947 ASSERT(texImage
->Height
> 0);
4948 ASSERT(texImage
->Depth
== 1);
4949 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4951 /* allocate storage for texture data */
4952 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4953 width
, height
, 1)) {
4954 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4958 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4960 "glCompressedTexImage2D");
4965 /* Map dest texture buffer (write to whole region) */
4966 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4967 0, 0, width
, height
,
4969 &dstMap
, &dstRowStride
);
4972 memcpy(dstMap
, data
, imageSize
);
4974 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4976 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4982 * Fallback for Driver.CompressedTexImage3D()
4985 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4986 GLenum target
, GLint level
,
4987 GLint internalFormat
,
4988 GLint width
, GLint height
, GLint depth
,
4990 GLsizei imageSize
, const GLvoid
*data
,
4991 struct gl_texture_object
*texObj
,
4992 struct gl_texture_image
*texImage
)
4994 /* this space intentionally left blank */
4996 (void) target
; (void) level
;
4997 (void) internalFormat
;
4998 (void) width
; (void) height
; (void) depth
;
5000 (void) imageSize
; (void) data
;
5008 * Fallback for Driver.CompressedTexSubImage1D()
5011 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
5013 GLint xoffset
, GLsizei width
,
5015 GLsizei imageSize
, const GLvoid
*data
,
5016 struct gl_texture_object
*texObj
,
5017 struct gl_texture_image
*texImage
)
5019 /* there are no compressed 1D texture formats yet */
5021 (void) target
; (void) level
;
5022 (void) xoffset
; (void) width
;
5024 (void) imageSize
; (void) data
;
5031 * Fallback for Driver.CompressedTexSubImage2D()
5034 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
5036 GLint xoffset
, GLint yoffset
,
5037 GLsizei width
, GLsizei height
,
5039 GLsizei imageSize
, const GLvoid
*data
,
5040 struct gl_texture_object
*texObj
,
5041 struct gl_texture_image
*texImage
)
5043 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
5047 const gl_format texFormat
= texImage
->TexFormat
;
5050 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
5052 /* these should have been caught sooner */
5053 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
5054 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
5055 ASSERT((xoffset
% bw
) == 0);
5056 ASSERT((yoffset
% bh
) == 0);
5058 /* get pointer to src pixels (may be in a pbo which we'll map here) */
5059 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
5061 "glCompressedTexSubImage2D");
5065 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
5066 src
= (const GLubyte
*) data
;
5068 /* Map dest texture buffer (write to whole region) */
5069 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
5070 xoffset
, yoffset
, width
, height
,
5072 &dstMap
, &dstRowStride
);
5074 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
5075 rows
= height
/ bh
; /* rows in blocks */
5077 /* copy rows of blocks */
5078 for (i
= 0; i
< rows
; i
++) {
5079 memcpy(dstMap
, src
, bytesPerRow
);
5080 dstMap
+= dstRowStride
;
5081 src
+= srcRowStride
;
5084 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
5086 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
5091 * Fallback for Driver.CompressedTexSubImage3D()
5094 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
5096 GLint xoffset
, GLint yoffset
, GLint zoffset
,
5097 GLsizei width
, GLsizei height
, GLsizei depth
,
5099 GLsizei imageSize
, const GLvoid
*data
,
5100 struct gl_texture_object
*texObj
,
5101 struct gl_texture_image
*texImage
)
5103 /* there are no compressed 3D texture formats yet */
5105 (void) target
; (void) level
;
5106 (void) xoffset
; (void) yoffset
; (void) zoffset
;
5107 (void) width
; (void) height
; (void) depth
;
5109 (void) imageSize
; (void) data
;