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"
64 #include "texcompress.h"
65 #include "texcompress_fxt1.h"
66 #include "texcompress_s3tc.h"
79 * Texture image storage function.
81 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
85 * Return GL_TRUE if the given image format is one that be converted
86 * to another format by swizzling.
89 can_swizzle(GLenum logicalBaseFormat
)
91 switch (logicalBaseFormat
) {
94 case GL_LUMINANCE_ALPHA
:
130 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
131 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
132 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
133 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
136 static const struct {
139 GLubyte from_rgba
[6];
140 } mappings
[MAX_IDX
] =
150 MAP4(ZERO
, ZERO
, ZERO
, 0),
180 MAP4(0, ZERO
, ZERO
, ONE
),
186 MAP4(ZERO
, 0, ZERO
, ONE
),
192 MAP4(ZERO
, ZERO
, 0, ONE
),
216 MAP4(0, 1, ZERO
, ONE
),
224 * Convert a GL image format enum to an IDX_* value (see above).
227 get_map_idx(GLenum value
)
230 case GL_LUMINANCE
: return IDX_LUMINANCE
;
231 case GL_ALPHA
: return IDX_ALPHA
;
232 case GL_INTENSITY
: return IDX_INTENSITY
;
233 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
234 case GL_RGB
: return IDX_RGB
;
235 case GL_RGBA
: return IDX_RGBA
;
236 case GL_RED
: return IDX_RED
;
237 case GL_GREEN
: return IDX_GREEN
;
238 case GL_BLUE
: return IDX_BLUE
;
239 case GL_BGR
: return IDX_BGR
;
240 case GL_BGRA
: return IDX_BGRA
;
241 case GL_ABGR_EXT
: return IDX_ABGR
;
242 case GL_RG
: return IDX_RG
;
244 _mesa_problem(NULL
, "Unexpected inFormat");
251 * When promoting texture formats (see below) we need to compute the
252 * mapping of dest components back to source components.
253 * This function does that.
254 * \param inFormat the incoming format of the texture
255 * \param outFormat the final texture format
256 * \return map[6] a full 6-component map
259 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
262 const int inFmt
= get_map_idx(inFormat
);
263 const int outFmt
= get_map_idx(outFormat
);
264 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
265 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
268 for (i
= 0; i
< 4; i
++)
269 map
[i
] = in2rgba
[rgba2out
[i
]];
275 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
276 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
277 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
289 * Make a temporary (color) texture image with GLfloat components.
290 * Apply all needed pixel unpacking and pixel transfer operations.
291 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
292 * Suppose the user specifies GL_LUMINANCE as the internal texture format
293 * but the graphics hardware doesn't support luminance textures. So, we might
294 * use an RGB hardware format instead.
295 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
297 * \param ctx the rendering context
298 * \param dims image dimensions: 1, 2 or 3
299 * \param logicalBaseFormat basic texture derived from the user's
300 * internal texture format value
301 * \param textureBaseFormat the actual basic format of the texture
302 * \param srcWidth source image width
303 * \param srcHeight source image height
304 * \param srcDepth source image depth
305 * \param srcFormat source image format
306 * \param srcType source image type
307 * \param srcAddr source image address
308 * \param srcPacking source image pixel packing
309 * \return resulting image with format = textureBaseFormat and type = GLfloat.
312 make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
313 GLenum logicalBaseFormat
,
314 GLenum textureBaseFormat
,
315 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
316 GLenum srcFormat
, GLenum srcType
,
317 const GLvoid
*srcAddr
,
318 const struct gl_pixelstore_attrib
*srcPacking
,
319 GLbitfield transferOps
)
322 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
323 const GLint srcStride
=
324 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
328 ASSERT(dims
>= 1 && dims
<= 3);
330 ASSERT(logicalBaseFormat
== GL_RGBA
||
331 logicalBaseFormat
== GL_RGB
||
332 logicalBaseFormat
== GL_RG
||
333 logicalBaseFormat
== GL_RED
||
334 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
335 logicalBaseFormat
== GL_LUMINANCE
||
336 logicalBaseFormat
== GL_ALPHA
||
337 logicalBaseFormat
== GL_INTENSITY
||
338 logicalBaseFormat
== GL_COLOR_INDEX
||
339 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
341 ASSERT(textureBaseFormat
== GL_RGBA
||
342 textureBaseFormat
== GL_RGB
||
343 textureBaseFormat
== GL_RG
||
344 textureBaseFormat
== GL_RED
||
345 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
346 textureBaseFormat
== GL_LUMINANCE
||
347 textureBaseFormat
== GL_ALPHA
||
348 textureBaseFormat
== GL_INTENSITY
||
349 textureBaseFormat
== GL_COLOR_INDEX
||
350 textureBaseFormat
== GL_DEPTH_COMPONENT
);
352 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
353 * components
* sizeof(GLfloat
));
358 for (img
= 0; img
< srcDepth
; img
++) {
360 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
364 for (row
= 0; row
< srcHeight
; row
++) {
365 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
366 dst
, srcFormat
, srcType
, src
,
367 srcPacking
, transferOps
);
368 dst
+= srcWidth
* components
;
373 if (logicalBaseFormat
!= textureBaseFormat
) {
375 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
376 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
381 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
382 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
383 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
385 /* The actual texture format should have at least as many components
386 * as the logical texture format.
388 ASSERT(texComponents
>= logComponents
);
390 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
391 * texComponents
* sizeof(GLfloat
));
397 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
399 n
= srcWidth
* srcHeight
* srcDepth
;
400 for (i
= 0; i
< n
; i
++) {
402 for (k
= 0; k
< texComponents
; k
++) {
405 newImage
[i
* texComponents
+ k
] = 0.0F
;
407 newImage
[i
* texComponents
+ k
] = 1.0F
;
409 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
414 tempImage
= newImage
;
422 * Make temporary image with uint pixel values. Used for unsigned
423 * integer-valued textures.
426 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
427 GLenum logicalBaseFormat
,
428 GLenum textureBaseFormat
,
429 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
430 GLenum srcFormat
, GLenum srcType
,
431 const GLvoid
*srcAddr
,
432 const struct gl_pixelstore_attrib
*srcPacking
)
435 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
436 const GLint srcStride
=
437 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
441 ASSERT(dims
>= 1 && dims
<= 3);
443 ASSERT(logicalBaseFormat
== GL_RGBA
||
444 logicalBaseFormat
== GL_RGB
||
445 logicalBaseFormat
== GL_RG
||
446 logicalBaseFormat
== GL_RED
||
447 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
448 logicalBaseFormat
== GL_LUMINANCE
||
449 logicalBaseFormat
== GL_INTENSITY
||
450 logicalBaseFormat
== GL_ALPHA
);
452 ASSERT(textureBaseFormat
== GL_RGBA
||
453 textureBaseFormat
== GL_RGB
||
454 textureBaseFormat
== GL_RG
||
455 textureBaseFormat
== GL_RED
||
456 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
457 textureBaseFormat
== GL_LUMINANCE
||
458 textureBaseFormat
== GL_ALPHA
);
460 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
461 * components
* sizeof(GLuint
));
466 for (img
= 0; img
< srcDepth
; img
++) {
468 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
472 for (row
= 0; row
< srcHeight
; row
++) {
473 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
474 dst
, srcFormat
, srcType
, src
,
476 dst
+= srcWidth
* components
;
481 if (logicalBaseFormat
!= textureBaseFormat
) {
483 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
484 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
489 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
490 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
491 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
493 /* The actual texture format should have at least as many components
494 * as the logical texture format.
496 ASSERT(texComponents
>= logComponents
);
498 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
499 * texComponents
* sizeof(GLuint
));
505 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
507 n
= srcWidth
* srcHeight
* srcDepth
;
508 for (i
= 0; i
< n
; i
++) {
510 for (k
= 0; k
< texComponents
; k
++) {
513 newImage
[i
* texComponents
+ k
] = 0.0F
;
515 newImage
[i
* texComponents
+ k
] = 1.0F
;
517 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
522 tempImage
= newImage
;
531 * Make a temporary (color) texture image with GLchan components.
532 * Apply all needed pixel unpacking and pixel transfer operations.
533 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
534 * Suppose the user specifies GL_LUMINANCE as the internal texture format
535 * but the graphics hardware doesn't support luminance textures. So, we might
536 * use an RGB hardware format instead.
537 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
539 * \param ctx the rendering context
540 * \param dims image dimensions: 1, 2 or 3
541 * \param logicalBaseFormat basic texture derived from the user's
542 * internal texture format value
543 * \param textureBaseFormat the actual basic format of the texture
544 * \param srcWidth source image width
545 * \param srcHeight source image height
546 * \param srcDepth source image depth
547 * \param srcFormat source image format
548 * \param srcType source image type
549 * \param srcAddr source image address
550 * \param srcPacking source image pixel packing
551 * \return resulting image with format = textureBaseFormat and type = GLchan.
554 _mesa_make_temp_chan_image(struct gl_context
*ctx
, GLuint dims
,
555 GLenum logicalBaseFormat
,
556 GLenum textureBaseFormat
,
557 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
558 GLenum srcFormat
, GLenum srcType
,
559 const GLvoid
*srcAddr
,
560 const struct gl_pixelstore_attrib
*srcPacking
)
562 GLuint transferOps
= ctx
->_ImageTransferState
;
563 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
565 GLchan
*tempImage
, *dst
;
567 ASSERT(dims
>= 1 && dims
<= 3);
569 ASSERT(logicalBaseFormat
== GL_RGBA
||
570 logicalBaseFormat
== GL_RGB
||
571 logicalBaseFormat
== GL_RG
||
572 logicalBaseFormat
== GL_RED
||
573 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
574 logicalBaseFormat
== GL_LUMINANCE
||
575 logicalBaseFormat
== GL_ALPHA
||
576 logicalBaseFormat
== GL_INTENSITY
);
578 ASSERT(textureBaseFormat
== GL_RGBA
||
579 textureBaseFormat
== GL_RGB
||
580 textureBaseFormat
== GL_RG
||
581 textureBaseFormat
== GL_RED
||
582 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
583 textureBaseFormat
== GL_LUMINANCE
||
584 textureBaseFormat
== GL_ALPHA
||
585 textureBaseFormat
== GL_INTENSITY
);
587 /* unpack and transfer the source image */
588 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
589 * components
* sizeof(GLchan
));
595 for (img
= 0; img
< srcDepth
; img
++) {
596 const GLint srcStride
=
597 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
599 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
603 for (row
= 0; row
< srcHeight
; row
++) {
604 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
605 srcFormat
, srcType
, src
, srcPacking
,
607 dst
+= srcWidth
* components
;
612 if (logicalBaseFormat
!= textureBaseFormat
) {
613 /* one more conversion step */
614 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
615 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
620 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
621 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
622 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
624 /* The actual texture format should have at least as many components
625 * as the logical texture format.
627 ASSERT(texComponents
>= logComponents
);
629 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
630 * texComponents
* sizeof(GLchan
));
636 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
638 n
= srcWidth
* srcHeight
* srcDepth
;
639 for (i
= 0; i
< n
; i
++) {
641 for (k
= 0; k
< texComponents
; k
++) {
644 newImage
[i
* texComponents
+ k
] = 0;
646 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
648 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
653 tempImage
= newImage
;
661 * Copy GLubyte pixels from <src> to <dst> with swizzling.
662 * \param dst destination pixels
663 * \param dstComponents number of color components in destination pixels
664 * \param src source pixels
665 * \param srcComponents number of color components in source pixels
666 * \param map the swizzle mapping. map[X] says where to find the X component
667 * in the source image's pixels. For example, if the source image
668 * is GL_BGRA and X = red, map[0] yields 2.
669 * \param count number of pixels to copy/swizzle.
672 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
673 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
675 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
678 for (i = 0; i < count; i++) { \
680 if (srcComps == 4) { \
681 COPY_4UBV(tmp, src); \
684 for (j = 0; j < srcComps; j++) { \
689 for (j = 0; j < dstComps; j++) { \
690 dst[j] = tmp[map[j]]; \
701 ASSERT(srcComponents
<= 4);
702 ASSERT(dstComponents
<= 4);
704 switch (dstComponents
) {
706 switch (srcComponents
) {
708 SWZ_CPY(dst
, src
, count
, 4, 4);
711 SWZ_CPY(dst
, src
, count
, 4, 3);
714 SWZ_CPY(dst
, src
, count
, 4, 2);
717 SWZ_CPY(dst
, src
, count
, 4, 1);
724 switch (srcComponents
) {
726 SWZ_CPY(dst
, src
, count
, 3, 4);
729 SWZ_CPY(dst
, src
, count
, 3, 3);
732 SWZ_CPY(dst
, src
, count
, 3, 2);
735 SWZ_CPY(dst
, src
, count
, 3, 1);
742 switch (srcComponents
) {
744 SWZ_CPY(dst
, src
, count
, 2, 4);
747 SWZ_CPY(dst
, src
, count
, 2, 3);
750 SWZ_CPY(dst
, src
, count
, 2, 2);
753 SWZ_CPY(dst
, src
, count
, 2, 1);
760 switch (srcComponents
) {
762 SWZ_CPY(dst
, src
, count
, 1, 4);
765 SWZ_CPY(dst
, src
, count
, 1, 3);
768 SWZ_CPY(dst
, src
, count
, 1, 2);
771 SWZ_CPY(dst
, src
, count
, 1, 1);
785 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
786 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
790 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
791 * mapping array depending on endianness.
793 static const GLubyte
*
794 type_mapping( GLenum srcType
)
798 case GL_UNSIGNED_BYTE
:
800 case GL_UNSIGNED_INT_8_8_8_8
:
801 return _mesa_little_endian() ? map_3210
: map_identity
;
802 case GL_UNSIGNED_INT_8_8_8_8_REV
:
803 return _mesa_little_endian() ? map_identity
: map_3210
;
811 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
812 * mapping array depending on pixelstore byte swapping state.
814 static const GLubyte
*
815 byteswap_mapping( GLboolean swapBytes
,
823 case GL_UNSIGNED_BYTE
:
825 case GL_UNSIGNED_INT_8_8_8_8
:
826 case GL_UNSIGNED_INT_8_8_8_8_REV
:
836 * Transfer a GLubyte texture image with component swizzling.
839 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
844 GLenum baseInternalFormat
,
846 const GLubyte
*rgba2dst
,
847 GLuint dstComponents
,
850 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
852 const GLuint
*dstImageOffsets
,
854 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
855 const GLvoid
*srcAddr
,
856 const struct gl_pixelstore_attrib
*srcPacking
)
858 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
859 const GLubyte
*srctype2ubyte
, *swap
;
860 GLubyte map
[4], src2base
[6], base2rgba
[6];
862 const GLint srcRowStride
=
863 _mesa_image_row_stride(srcPacking
, srcWidth
,
864 srcFormat
, GL_UNSIGNED_BYTE
);
865 const GLint srcImageStride
866 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
868 const GLubyte
*srcImage
869 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
870 srcWidth
, srcHeight
, srcFormat
,
871 GL_UNSIGNED_BYTE
, 0, 0, 0);
875 /* Translate from src->baseInternal->GL_RGBA->dst. This will
876 * correctly deal with RGBA->RGB->RGBA conversions where the final
877 * A value must be 0xff regardless of the incoming alpha values.
879 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
880 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
881 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
882 srctype2ubyte
= type_mapping(srcType
);
885 for (i
= 0; i
< 4; i
++)
886 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
888 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
890 if (srcComponents
== dstComponents
&&
891 srcRowStride
== dstRowStride
&&
892 srcRowStride
== srcWidth
* srcComponents
&&
894 /* 1 and 2D images only */
895 GLubyte
*dstImage
= (GLubyte
*) dstAddr
896 + dstYoffset
* dstRowStride
897 + dstXoffset
* dstComponents
;
898 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
899 srcWidth
* srcHeight
);
903 for (img
= 0; img
< srcDepth
; img
++) {
904 const GLubyte
*srcRow
= srcImage
;
905 GLubyte
*dstRow
= (GLubyte
*) dstAddr
906 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
907 + dstYoffset
* dstRowStride
908 + dstXoffset
* dstComponents
;
909 for (row
= 0; row
< srcHeight
; row
++) {
910 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
911 dstRow
+= dstRowStride
;
912 srcRow
+= srcRowStride
;
914 srcImage
+= srcImageStride
;
921 * Teximage storage routine for when a simple memcpy will do.
922 * No pixel transfer operations or special texel encodings allowed.
923 * 1D, 2D and 3D images supported.
926 memcpy_texture(struct gl_context
*ctx
,
930 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
932 const GLuint
*dstImageOffsets
,
933 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
934 GLenum srcFormat
, GLenum srcType
,
935 const GLvoid
*srcAddr
,
936 const struct gl_pixelstore_attrib
*srcPacking
)
938 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
940 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
941 srcWidth
, srcHeight
, srcFormat
, srcType
);
942 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
943 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
944 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
945 const GLint bytesPerRow
= srcWidth
* texelBytes
;
948 /* XXX update/re-enable for dstImageOffsets array */
949 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
950 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
951 GLubyte
*dstImage
= (GLubyte
*) dstAddr
952 + dstZoffset
* dstImageStride
953 + dstYoffset
* dstRowStride
954 + dstXoffset
* texelBytes
;
956 if (dstRowStride
== srcRowStride
&&
957 dstRowStride
== bytesPerRow
&&
958 ((dstImageStride
== srcImageStride
&&
959 dstImageStride
== bytesPerImage
) ||
962 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
967 for (img
= 0; img
< srcDepth
; img
++) {
968 const GLubyte
*srcRow
= srcImage
;
969 GLubyte
*dstRow
= dstImage
;
970 for (row
= 0; row
< srcHeight
; row
++) {
971 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
972 dstRow
+= dstRowStride
;
973 srcRow
+= srcRowStride
;
975 srcImage
+= srcImageStride
;
976 dstImage
+= dstImageStride
;
982 for (img
= 0; img
< srcDepth
; img
++) {
983 const GLubyte
*srcRow
= srcImage
;
984 GLubyte
*dstRow
= (GLubyte
*) dstAddr
985 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
986 + dstYoffset
* dstRowStride
987 + dstXoffset
* texelBytes
;
988 for (row
= 0; row
< srcHeight
; row
++) {
989 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
990 dstRow
+= dstRowStride
;
991 srcRow
+= srcRowStride
;
993 srcImage
+= srcImageStride
;
1000 * Store a 32-bit integer depth component texture image.
1003 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1005 const GLuint depthScale
= 0xffffffff;
1006 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1008 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1009 ASSERT(texelBytes
== sizeof(GLuint
));
1011 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1012 ctx
->Pixel
.DepthBias
== 0.0f
&&
1013 !srcPacking
->SwapBytes
&&
1014 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1015 srcFormat
== GL_DEPTH_COMPONENT
&&
1016 srcType
== GL_UNSIGNED_INT
) {
1017 /* simple memcpy path */
1018 memcpy_texture(ctx
, dims
,
1019 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1022 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1023 srcAddr
, srcPacking
);
1028 for (img
= 0; img
< srcDepth
; img
++) {
1029 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1030 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1031 + dstYoffset
* dstRowStride
1032 + dstXoffset
* texelBytes
;
1033 for (row
= 0; row
< srcHeight
; row
++) {
1034 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1035 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1036 _mesa_unpack_depth_span(ctx
, srcWidth
,
1037 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1038 depthScale
, srcType
, src
, srcPacking
);
1039 dstRow
+= dstRowStride
;
1048 * Store a 24-bit integer depth component texture image.
1051 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1053 const GLuint depthScale
= 0xffffff;
1054 const GLuint texelBytes
= 4;
1057 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1062 for (img
= 0; img
< srcDepth
; img
++) {
1063 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1064 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1065 + dstYoffset
* dstRowStride
1066 + dstXoffset
* texelBytes
;
1067 for (row
= 0; row
< srcHeight
; row
++) {
1068 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1069 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1070 _mesa_unpack_depth_span(ctx
, srcWidth
,
1071 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1072 depthScale
, srcType
, src
, srcPacking
);
1073 dstRow
+= dstRowStride
;
1082 * Store a 24-bit integer depth component texture image.
1085 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1087 const GLuint depthScale
= 0xffffff;
1088 const GLuint texelBytes
= 4;
1091 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1096 for (img
= 0; img
< srcDepth
; img
++) {
1097 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1098 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1099 + dstYoffset
* dstRowStride
1100 + dstXoffset
* texelBytes
;
1101 for (row
= 0; row
< srcHeight
; row
++) {
1102 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1103 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1104 GLuint
*dst
= (GLuint
*) dstRow
;
1106 _mesa_unpack_depth_span(ctx
, srcWidth
,
1107 GL_UNSIGNED_INT
, dst
,
1108 depthScale
, srcType
, src
, srcPacking
);
1109 for (i
= 0; i
< srcWidth
; i
++)
1111 dstRow
+= dstRowStride
;
1120 * Store a 16-bit integer depth component texture image.
1123 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1125 const GLuint depthScale
= 0xffff;
1126 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1128 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1129 ASSERT(texelBytes
== sizeof(GLushort
));
1131 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1132 ctx
->Pixel
.DepthBias
== 0.0f
&&
1133 !srcPacking
->SwapBytes
&&
1134 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1135 srcFormat
== GL_DEPTH_COMPONENT
&&
1136 srcType
== GL_UNSIGNED_SHORT
) {
1137 /* simple memcpy path */
1138 memcpy_texture(ctx
, dims
,
1139 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1142 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1143 srcAddr
, srcPacking
);
1148 for (img
= 0; img
< srcDepth
; img
++) {
1149 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1150 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1151 + dstYoffset
* dstRowStride
1152 + dstXoffset
* texelBytes
;
1153 for (row
= 0; row
< srcHeight
; row
++) {
1154 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1155 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1156 GLushort
*dst16
= (GLushort
*) dstRow
;
1157 _mesa_unpack_depth_span(ctx
, srcWidth
,
1158 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1159 srcType
, src
, srcPacking
);
1160 dstRow
+= dstRowStride
;
1169 * Store an rgb565 or rgb565_rev texture image.
1172 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1174 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1175 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1177 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1178 dstFormat
== MESA_FORMAT_RGB565_REV
);
1179 ASSERT(texelBytes
== 2);
1181 if (!ctx
->_ImageTransferState
&&
1182 !srcPacking
->SwapBytes
&&
1183 dstFormat
== MESA_FORMAT_RGB565
&&
1184 baseInternalFormat
== GL_RGB
&&
1185 srcFormat
== GL_RGB
&&
1186 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1187 /* simple memcpy path */
1188 memcpy_texture(ctx
, dims
,
1189 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1192 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1193 srcAddr
, srcPacking
);
1195 else if (!ctx
->_ImageTransferState
&&
1196 !srcPacking
->SwapBytes
&&
1197 baseInternalFormat
== GL_RGB
&&
1198 srcFormat
== GL_RGB
&&
1199 srcType
== GL_UNSIGNED_BYTE
&&
1201 /* do optimized tex store */
1202 const GLint srcRowStride
=
1203 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1204 const GLubyte
*src
= (const GLubyte
*)
1205 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1206 srcFormat
, srcType
, 0, 0, 0);
1207 GLubyte
*dst
= (GLubyte
*) dstAddr
1208 + dstYoffset
* dstRowStride
1209 + dstXoffset
* texelBytes
;
1211 for (row
= 0; row
< srcHeight
; row
++) {
1212 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1213 GLushort
*dstUS
= (GLushort
*) dst
;
1214 /* check for byteswapped format */
1215 if (dstFormat
== MESA_FORMAT_RGB565
) {
1216 for (col
= 0; col
< srcWidth
; col
++) {
1217 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1222 for (col
= 0; col
< srcWidth
; col
++) {
1223 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1227 dst
+= dstRowStride
;
1228 src
+= srcRowStride
;
1233 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1236 srcWidth
, srcHeight
, srcDepth
,
1237 srcFormat
, srcType
, srcAddr
,
1239 const GLchan
*src
= tempImage
;
1240 GLint img
, row
, col
;
1243 for (img
= 0; img
< srcDepth
; img
++) {
1244 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1245 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1246 + dstYoffset
* dstRowStride
1247 + dstXoffset
* texelBytes
;
1248 for (row
= 0; row
< srcHeight
; row
++) {
1249 GLushort
*dstUS
= (GLushort
*) dstRow
;
1250 /* check for byteswapped format */
1251 if (dstFormat
== MESA_FORMAT_RGB565
) {
1252 for (col
= 0; col
< srcWidth
; col
++) {
1253 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1254 CHAN_TO_UBYTE(src
[GCOMP
]),
1255 CHAN_TO_UBYTE(src
[BCOMP
]) );
1260 for (col
= 0; col
< srcWidth
; col
++) {
1261 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1262 CHAN_TO_UBYTE(src
[GCOMP
]),
1263 CHAN_TO_UBYTE(src
[BCOMP
]) );
1267 dstRow
+= dstRowStride
;
1270 free((void *) tempImage
);
1277 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1280 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1282 const GLboolean littleEndian
= _mesa_little_endian();
1283 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1284 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1286 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1287 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1288 ASSERT(texelBytes
== 4);
1290 if (!ctx
->_ImageTransferState
&&
1291 !srcPacking
->SwapBytes
&&
1292 dstFormat
== MESA_FORMAT_RGBA8888
&&
1293 baseInternalFormat
== GL_RGBA
&&
1294 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1295 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1296 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1297 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1298 /* simple memcpy path */
1299 memcpy_texture(ctx
, dims
,
1300 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1303 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1304 srcAddr
, srcPacking
);
1306 else if (!ctx
->_ImageTransferState
&&
1307 !srcPacking
->SwapBytes
&&
1308 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1309 baseInternalFormat
== GL_RGBA
&&
1310 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1311 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1312 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1313 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1314 /* simple memcpy path */
1315 memcpy_texture(ctx
, dims
,
1316 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1319 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1320 srcAddr
, srcPacking
);
1322 else if (!ctx
->_ImageTransferState
&&
1323 (srcType
== GL_UNSIGNED_BYTE
||
1324 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1325 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1326 can_swizzle(baseInternalFormat
) &&
1327 can_swizzle(srcFormat
)) {
1331 /* dstmap - how to swizzle from RGBA to dst format:
1333 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1334 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1347 _mesa_swizzle_ubyte_image(ctx
, dims
,
1352 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1353 dstRowStride
, dstImageOffsets
,
1354 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1359 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1362 srcWidth
, srcHeight
, srcDepth
,
1363 srcFormat
, srcType
, srcAddr
,
1365 const GLchan
*src
= tempImage
;
1366 GLint img
, row
, col
;
1369 for (img
= 0; img
< srcDepth
; img
++) {
1370 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1371 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1372 + dstYoffset
* dstRowStride
1373 + dstXoffset
* texelBytes
;
1374 for (row
= 0; row
< srcHeight
; row
++) {
1375 GLuint
*dstUI
= (GLuint
*) dstRow
;
1376 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1377 for (col
= 0; col
< srcWidth
; col
++) {
1378 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1379 CHAN_TO_UBYTE(src
[GCOMP
]),
1380 CHAN_TO_UBYTE(src
[BCOMP
]),
1381 CHAN_TO_UBYTE(src
[ACOMP
]) );
1386 for (col
= 0; col
< srcWidth
; col
++) {
1387 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1388 CHAN_TO_UBYTE(src
[GCOMP
]),
1389 CHAN_TO_UBYTE(src
[BCOMP
]),
1390 CHAN_TO_UBYTE(src
[ACOMP
]) );
1394 dstRow
+= dstRowStride
;
1397 free((void *) tempImage
);
1404 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1406 const GLboolean littleEndian
= _mesa_little_endian();
1407 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1408 const GLenum baseFormat
= GL_RGBA
;
1410 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1411 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1412 dstFormat
== MESA_FORMAT_XRGB8888
||
1413 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1414 ASSERT(texelBytes
== 4);
1416 if (!ctx
->_ImageTransferState
&&
1417 !srcPacking
->SwapBytes
&&
1418 (dstFormat
== MESA_FORMAT_ARGB8888
||
1419 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1420 baseInternalFormat
== GL_RGBA
&&
1421 srcFormat
== GL_BGRA
&&
1422 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1423 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1424 /* simple memcpy path (little endian) */
1425 memcpy_texture(ctx
, dims
,
1426 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1429 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1430 srcAddr
, srcPacking
);
1432 else if (!ctx
->_ImageTransferState
&&
1433 !srcPacking
->SwapBytes
&&
1434 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1435 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1436 baseInternalFormat
== GL_RGBA
&&
1437 srcFormat
== GL_BGRA
&&
1438 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1439 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1440 /* simple memcpy path (big endian) */
1441 memcpy_texture(ctx
, dims
,
1442 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1445 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1446 srcAddr
, srcPacking
);
1448 else if (!ctx
->_ImageTransferState
&&
1449 !srcPacking
->SwapBytes
&&
1450 (dstFormat
== MESA_FORMAT_ARGB8888
||
1451 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1452 srcFormat
== GL_RGB
&&
1453 (baseInternalFormat
== GL_RGBA
||
1454 baseInternalFormat
== GL_RGB
) &&
1455 srcType
== GL_UNSIGNED_BYTE
) {
1457 for (img
= 0; img
< srcDepth
; img
++) {
1458 const GLint srcRowStride
=
1459 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1460 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1461 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1462 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1463 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1464 + dstYoffset
* dstRowStride
1465 + dstXoffset
* texelBytes
;
1466 for (row
= 0; row
< srcHeight
; row
++) {
1467 GLuint
*d4
= (GLuint
*) dstRow
;
1468 for (col
= 0; col
< srcWidth
; col
++) {
1469 d4
[col
] = PACK_COLOR_8888(0xff,
1470 srcRow
[col
* 3 + RCOMP
],
1471 srcRow
[col
* 3 + GCOMP
],
1472 srcRow
[col
* 3 + BCOMP
]);
1474 dstRow
+= dstRowStride
;
1475 srcRow
+= srcRowStride
;
1479 else if (!ctx
->_ImageTransferState
&&
1480 !srcPacking
->SwapBytes
&&
1481 dstFormat
== MESA_FORMAT_ARGB8888
&&
1482 srcFormat
== GL_RGBA
&&
1483 baseInternalFormat
== GL_RGBA
&&
1484 srcType
== GL_UNSIGNED_BYTE
) {
1485 /* same as above case, but src data has alpha too */
1486 GLint img
, row
, col
;
1487 /* For some reason, streaming copies to write-combined regions
1488 * are extremely sensitive to the characteristics of how the
1489 * source data is retrieved. By reordering the source reads to
1490 * be in-order, the speed of this operation increases by half.
1491 * Strangely the same isn't required for the RGB path, above.
1493 for (img
= 0; img
< srcDepth
; img
++) {
1494 const GLint srcRowStride
=
1495 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1496 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1497 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1498 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1499 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1500 + dstYoffset
* dstRowStride
1501 + dstXoffset
* texelBytes
;
1502 for (row
= 0; row
< srcHeight
; row
++) {
1503 GLuint
*d4
= (GLuint
*) dstRow
;
1504 for (col
= 0; col
< srcWidth
; col
++) {
1505 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1506 srcRow
[col
* 4 + RCOMP
],
1507 srcRow
[col
* 4 + GCOMP
],
1508 srcRow
[col
* 4 + BCOMP
]);
1510 dstRow
+= dstRowStride
;
1511 srcRow
+= srcRowStride
;
1515 else if (!ctx
->_ImageTransferState
&&
1516 (srcType
== GL_UNSIGNED_BYTE
||
1517 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1518 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1519 can_swizzle(baseInternalFormat
) &&
1520 can_swizzle(srcFormat
)) {
1524 /* dstmap - how to swizzle from RGBA to dst format:
1526 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1527 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1528 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1529 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1530 dstmap
[3] = 3; /* alpha */
1531 dstmap
[2] = 0; /* red */
1532 dstmap
[1] = 1; /* green */
1533 dstmap
[0] = 2; /* blue */
1536 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1537 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1538 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1539 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1546 _mesa_swizzle_ubyte_image(ctx
, dims
,
1551 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1554 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1559 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1562 srcWidth
, srcHeight
, srcDepth
,
1563 srcFormat
, srcType
, srcAddr
,
1565 const GLchan
*src
= tempImage
;
1566 GLint img
, row
, col
;
1569 for (img
= 0; img
< srcDepth
; img
++) {
1570 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1571 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1572 + dstYoffset
* dstRowStride
1573 + dstXoffset
* texelBytes
;
1574 for (row
= 0; row
< srcHeight
; row
++) {
1575 GLuint
*dstUI
= (GLuint
*) dstRow
;
1576 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1577 for (col
= 0; col
< srcWidth
; col
++) {
1578 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1579 CHAN_TO_UBYTE(src
[RCOMP
]),
1580 CHAN_TO_UBYTE(src
[GCOMP
]),
1581 CHAN_TO_UBYTE(src
[BCOMP
]) );
1585 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1586 for (col
= 0; col
< srcWidth
; col
++) {
1587 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1588 CHAN_TO_UBYTE(src
[RCOMP
]),
1589 CHAN_TO_UBYTE(src
[GCOMP
]),
1590 CHAN_TO_UBYTE(src
[BCOMP
]) );
1595 for (col
= 0; col
< srcWidth
; col
++) {
1596 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1597 CHAN_TO_UBYTE(src
[RCOMP
]),
1598 CHAN_TO_UBYTE(src
[GCOMP
]),
1599 CHAN_TO_UBYTE(src
[BCOMP
]) );
1603 dstRow
+= dstRowStride
;
1606 free((void *) tempImage
);
1613 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1615 const GLboolean littleEndian
= _mesa_little_endian();
1616 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1617 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1619 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1620 ASSERT(texelBytes
== 3);
1622 if (!ctx
->_ImageTransferState
&&
1623 !srcPacking
->SwapBytes
&&
1624 baseInternalFormat
== GL_RGB
&&
1625 srcFormat
== GL_BGR
&&
1626 srcType
== GL_UNSIGNED_BYTE
&&
1628 /* simple memcpy path */
1629 memcpy_texture(ctx
, dims
,
1630 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1633 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1634 srcAddr
, srcPacking
);
1636 else if (!ctx
->_ImageTransferState
&&
1637 !srcPacking
->SwapBytes
&&
1638 srcFormat
== GL_RGBA
&&
1639 srcType
== GL_UNSIGNED_BYTE
) {
1640 /* extract RGB from RGBA */
1641 GLint img
, row
, col
;
1642 for (img
= 0; img
< srcDepth
; img
++) {
1643 const GLint srcRowStride
=
1644 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1645 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1646 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1647 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1648 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1649 + dstYoffset
* dstRowStride
1650 + dstXoffset
* texelBytes
;
1651 for (row
= 0; row
< srcHeight
; row
++) {
1652 for (col
= 0; col
< srcWidth
; col
++) {
1653 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1654 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1655 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1657 dstRow
+= dstRowStride
;
1658 srcRow
+= srcRowStride
;
1662 else if (!ctx
->_ImageTransferState
&&
1663 srcType
== GL_UNSIGNED_BYTE
&&
1664 can_swizzle(baseInternalFormat
) &&
1665 can_swizzle(srcFormat
)) {
1669 /* dstmap - how to swizzle from RGBA to dst format:
1674 dstmap
[3] = ONE
; /* ? */
1676 _mesa_swizzle_ubyte_image(ctx
, dims
,
1681 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1682 dstRowStride
, dstImageOffsets
,
1683 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1688 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1691 srcWidth
, srcHeight
, srcDepth
,
1692 srcFormat
, srcType
, srcAddr
,
1694 const GLchan
*src
= (const GLchan
*) tempImage
;
1695 GLint img
, row
, col
;
1698 for (img
= 0; img
< srcDepth
; img
++) {
1699 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1700 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1701 + dstYoffset
* dstRowStride
1702 + dstXoffset
* texelBytes
;
1703 for (row
= 0; row
< srcHeight
; row
++) {
1706 for (col
= 0; col
< srcWidth
; col
++) {
1707 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1708 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1709 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1714 for (col
= 0; col
< srcWidth
; col
++) {
1715 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1716 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1717 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1722 for (col
= 0; col
< srcWidth
; col
++) {
1723 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1724 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1725 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1729 dstRow
+= dstRowStride
;
1732 free((void *) tempImage
);
1739 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1741 const GLboolean littleEndian
= _mesa_little_endian();
1742 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1743 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1745 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1746 ASSERT(texelBytes
== 3);
1748 if (!ctx
->_ImageTransferState
&&
1749 !srcPacking
->SwapBytes
&&
1750 baseInternalFormat
== GL_RGB
&&
1751 srcFormat
== GL_RGB
&&
1752 srcType
== GL_UNSIGNED_BYTE
&&
1754 /* simple memcpy path */
1755 memcpy_texture(ctx
, dims
,
1756 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1759 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1760 srcAddr
, srcPacking
);
1762 else if (!ctx
->_ImageTransferState
&&
1763 !srcPacking
->SwapBytes
&&
1764 srcFormat
== GL_RGBA
&&
1765 srcType
== GL_UNSIGNED_BYTE
) {
1766 /* extract BGR from RGBA */
1768 for (img
= 0; img
< srcDepth
; img
++) {
1769 const GLint srcRowStride
=
1770 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1771 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1772 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1773 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1774 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1775 + dstYoffset
* dstRowStride
1776 + dstXoffset
* texelBytes
;
1777 for (row
= 0; row
< srcHeight
; row
++) {
1778 for (col
= 0; col
< srcWidth
; col
++) {
1779 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1780 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1781 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1783 dstRow
+= dstRowStride
;
1784 srcRow
+= srcRowStride
;
1788 else if (!ctx
->_ImageTransferState
&&
1789 srcType
== GL_UNSIGNED_BYTE
&&
1790 can_swizzle(baseInternalFormat
) &&
1791 can_swizzle(srcFormat
)) {
1795 /* dstmap - how to swizzle from RGBA to dst format:
1800 dstmap
[3] = ONE
; /* ? */
1802 _mesa_swizzle_ubyte_image(ctx
, dims
,
1807 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1808 dstRowStride
, dstImageOffsets
,
1809 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1814 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1817 srcWidth
, srcHeight
, srcDepth
,
1818 srcFormat
, srcType
, srcAddr
,
1820 const GLchan
*src
= (const GLchan
*) tempImage
;
1821 GLint img
, row
, col
;
1824 for (img
= 0; img
< srcDepth
; img
++) {
1825 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1826 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1827 + dstYoffset
* dstRowStride
1828 + dstXoffset
* texelBytes
;
1829 for (row
= 0; row
< srcHeight
; row
++) {
1830 for (col
= 0; col
< srcWidth
; col
++) {
1831 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1832 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1833 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1836 dstRow
+= dstRowStride
;
1839 free((void *) tempImage
);
1846 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1848 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1849 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1851 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1852 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1853 ASSERT(texelBytes
== 2);
1855 if (!ctx
->_ImageTransferState
&&
1856 !srcPacking
->SwapBytes
&&
1857 dstFormat
== MESA_FORMAT_ARGB4444
&&
1858 baseInternalFormat
== GL_RGBA
&&
1859 srcFormat
== GL_BGRA
&&
1860 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1861 /* simple memcpy path */
1862 memcpy_texture(ctx
, dims
,
1863 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1866 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1867 srcAddr
, srcPacking
);
1871 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1874 srcWidth
, srcHeight
, srcDepth
,
1875 srcFormat
, srcType
, srcAddr
,
1877 const GLchan
*src
= tempImage
;
1878 GLint img
, row
, col
;
1881 for (img
= 0; img
< srcDepth
; img
++) {
1882 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1883 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1884 + dstYoffset
* dstRowStride
1885 + dstXoffset
* texelBytes
;
1886 for (row
= 0; row
< srcHeight
; row
++) {
1887 GLushort
*dstUS
= (GLushort
*) dstRow
;
1888 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1889 for (col
= 0; col
< srcWidth
; col
++) {
1890 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1891 CHAN_TO_UBYTE(src
[RCOMP
]),
1892 CHAN_TO_UBYTE(src
[GCOMP
]),
1893 CHAN_TO_UBYTE(src
[BCOMP
]) );
1898 for (col
= 0; col
< srcWidth
; col
++) {
1899 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1900 CHAN_TO_UBYTE(src
[RCOMP
]),
1901 CHAN_TO_UBYTE(src
[GCOMP
]),
1902 CHAN_TO_UBYTE(src
[BCOMP
]) );
1906 dstRow
+= dstRowStride
;
1909 free((void *) tempImage
);
1915 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1917 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1918 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1920 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1921 ASSERT(texelBytes
== 2);
1923 if (!ctx
->_ImageTransferState
&&
1924 !srcPacking
->SwapBytes
&&
1925 dstFormat
== MESA_FORMAT_RGBA5551
&&
1926 baseInternalFormat
== GL_RGBA
&&
1927 srcFormat
== GL_RGBA
&&
1928 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1929 /* simple memcpy path */
1930 memcpy_texture(ctx
, dims
,
1931 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1934 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1935 srcAddr
, srcPacking
);
1939 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1942 srcWidth
, srcHeight
, srcDepth
,
1943 srcFormat
, srcType
, srcAddr
,
1945 const GLchan
*src
=tempImage
;
1946 GLint img
, row
, col
;
1949 for (img
= 0; img
< srcDepth
; img
++) {
1950 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1951 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1952 + dstYoffset
* dstRowStride
1953 + dstXoffset
* texelBytes
;
1954 for (row
= 0; row
< srcHeight
; row
++) {
1955 GLushort
*dstUS
= (GLushort
*) dstRow
;
1956 for (col
= 0; col
< srcWidth
; col
++) {
1957 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1958 CHAN_TO_UBYTE(src
[GCOMP
]),
1959 CHAN_TO_UBYTE(src
[BCOMP
]),
1960 CHAN_TO_UBYTE(src
[ACOMP
]) );
1963 dstRow
+= dstRowStride
;
1966 free((void *) tempImage
);
1972 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1974 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1975 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1977 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1978 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1979 ASSERT(texelBytes
== 2);
1981 if (!ctx
->_ImageTransferState
&&
1982 !srcPacking
->SwapBytes
&&
1983 dstFormat
== MESA_FORMAT_ARGB1555
&&
1984 baseInternalFormat
== GL_RGBA
&&
1985 srcFormat
== GL_BGRA
&&
1986 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1987 /* simple memcpy path */
1988 memcpy_texture(ctx
, dims
,
1989 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1992 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1993 srcAddr
, srcPacking
);
1997 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2000 srcWidth
, srcHeight
, srcDepth
,
2001 srcFormat
, srcType
, srcAddr
,
2003 const GLchan
*src
=tempImage
;
2004 GLint img
, row
, col
;
2007 for (img
= 0; img
< srcDepth
; img
++) {
2008 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2009 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2010 + dstYoffset
* dstRowStride
2011 + dstXoffset
* texelBytes
;
2012 for (row
= 0; row
< srcHeight
; row
++) {
2013 GLushort
*dstUS
= (GLushort
*) dstRow
;
2014 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
2015 for (col
= 0; col
< srcWidth
; col
++) {
2016 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
2017 CHAN_TO_UBYTE(src
[RCOMP
]),
2018 CHAN_TO_UBYTE(src
[GCOMP
]),
2019 CHAN_TO_UBYTE(src
[BCOMP
]) );
2024 for (col
= 0; col
< srcWidth
; col
++) {
2025 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2026 CHAN_TO_UBYTE(src
[RCOMP
]),
2027 CHAN_TO_UBYTE(src
[GCOMP
]),
2028 CHAN_TO_UBYTE(src
[BCOMP
]) );
2032 dstRow
+= dstRowStride
;
2035 free((void *) tempImage
);
2042 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2045 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2047 const GLboolean littleEndian
= _mesa_little_endian();
2048 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2049 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2051 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2052 dstFormat
== MESA_FORMAT_AL88_REV
||
2053 dstFormat
== MESA_FORMAT_RG88
||
2054 dstFormat
== MESA_FORMAT_RG88_REV
);
2055 ASSERT(texelBytes
== 2);
2057 if (!ctx
->_ImageTransferState
&&
2058 !srcPacking
->SwapBytes
&&
2059 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
2060 baseInternalFormat
== srcFormat
&&
2061 srcType
== GL_UNSIGNED_BYTE
&&
2063 /* simple memcpy path */
2064 memcpy_texture(ctx
, dims
,
2065 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2068 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2069 srcAddr
, srcPacking
);
2071 else if (!ctx
->_ImageTransferState
&&
2073 srcType
== GL_UNSIGNED_BYTE
&&
2074 can_swizzle(baseInternalFormat
) &&
2075 can_swizzle(srcFormat
)) {
2078 /* dstmap - how to swizzle from RGBA to dst format:
2080 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2081 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2082 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2092 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2093 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2102 dstmap
[2] = ZERO
; /* ? */
2103 dstmap
[3] = ONE
; /* ? */
2105 _mesa_swizzle_ubyte_image(ctx
, dims
,
2110 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2111 dstRowStride
, dstImageOffsets
,
2112 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2117 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2120 srcWidth
, srcHeight
, srcDepth
,
2121 srcFormat
, srcType
, srcAddr
,
2123 const GLchan
*src
= tempImage
;
2124 GLint img
, row
, col
;
2127 for (img
= 0; img
< srcDepth
; img
++) {
2128 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2129 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2130 + dstYoffset
* dstRowStride
2131 + dstXoffset
* texelBytes
;
2132 for (row
= 0; row
< srcHeight
; row
++) {
2133 GLushort
*dstUS
= (GLushort
*) dstRow
;
2134 if (dstFormat
== MESA_FORMAT_AL88
||
2135 dstFormat
== MESA_FORMAT_RG88
) {
2136 for (col
= 0; col
< srcWidth
; col
++) {
2137 /* src[0] is luminance, src[1] is alpha */
2138 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2139 CHAN_TO_UBYTE(src
[0]) );
2144 for (col
= 0; col
< srcWidth
; col
++) {
2145 /* src[0] is luminance, src[1] is alpha */
2146 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2147 CHAN_TO_UBYTE(src
[0]) );
2151 dstRow
+= dstRowStride
;
2154 free((void *) tempImage
);
2161 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2164 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2166 const GLboolean littleEndian
= _mesa_little_endian();
2167 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2168 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2170 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2171 dstFormat
== MESA_FORMAT_AL1616_REV
||
2172 dstFormat
== MESA_FORMAT_RG1616
||
2173 dstFormat
== MESA_FORMAT_RG1616_REV
);
2174 ASSERT(texelBytes
== 4);
2176 if (!ctx
->_ImageTransferState
&&
2177 !srcPacking
->SwapBytes
&&
2178 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2179 baseInternalFormat
== srcFormat
&&
2180 srcType
== GL_UNSIGNED_SHORT
&&
2182 /* simple memcpy path */
2183 memcpy_texture(ctx
, dims
,
2184 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2187 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2188 srcAddr
, srcPacking
);
2192 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2195 srcWidth
, srcHeight
, srcDepth
,
2196 srcFormat
, srcType
, srcAddr
,
2198 ctx
->_ImageTransferState
);
2199 const GLfloat
*src
= tempImage
;
2200 GLint img
, row
, col
;
2203 for (img
= 0; img
< srcDepth
; img
++) {
2204 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2205 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2206 + dstYoffset
* dstRowStride
2207 + dstXoffset
* texelBytes
;
2208 for (row
= 0; row
< srcHeight
; row
++) {
2209 GLuint
*dstUI
= (GLuint
*) dstRow
;
2210 if (dstFormat
== MESA_FORMAT_AL1616
||
2211 dstFormat
== MESA_FORMAT_RG1616
) {
2212 for (col
= 0; col
< srcWidth
; col
++) {
2215 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2216 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2217 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2222 for (col
= 0; col
< srcWidth
; col
++) {
2225 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2226 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2227 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2231 dstRow
+= dstRowStride
;
2234 free((void *) tempImage
);
2241 _mesa_texstore_r16(TEXSTORE_PARAMS
)
2243 const GLboolean littleEndian
= _mesa_little_endian();
2244 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2245 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2247 ASSERT(dstFormat
== MESA_FORMAT_R16
);
2248 ASSERT(texelBytes
== 2);
2250 if (!ctx
->_ImageTransferState
&&
2251 !srcPacking
->SwapBytes
&&
2252 dstFormat
== MESA_FORMAT_R16
&&
2253 baseInternalFormat
== GL_RED
&&
2254 srcFormat
== GL_RED
&&
2255 srcType
== GL_UNSIGNED_SHORT
&&
2257 /* simple memcpy path */
2258 memcpy_texture(ctx
, dims
,
2259 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2262 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2263 srcAddr
, srcPacking
);
2267 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2270 srcWidth
, srcHeight
, srcDepth
,
2271 srcFormat
, srcType
, srcAddr
,
2273 ctx
->_ImageTransferState
);
2274 const GLfloat
*src
= tempImage
;
2275 GLint img
, row
, col
;
2278 for (img
= 0; img
< srcDepth
; img
++) {
2279 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2280 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2281 + dstYoffset
* dstRowStride
2282 + dstXoffset
* texelBytes
;
2283 for (row
= 0; row
< srcHeight
; row
++) {
2284 GLushort
*dstUS
= (GLushort
*) dstRow
;
2285 for (col
= 0; col
< srcWidth
; col
++) {
2288 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2292 dstRow
+= dstRowStride
;
2295 free((void *) tempImage
);
2302 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2304 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2305 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2307 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2308 ASSERT(texelBytes
== 8);
2310 if (!ctx
->_ImageTransferState
&&
2311 !srcPacking
->SwapBytes
&&
2312 baseInternalFormat
== GL_RGBA
&&
2313 srcFormat
== GL_RGBA
&&
2314 srcType
== GL_UNSIGNED_SHORT
) {
2315 /* simple memcpy path */
2316 memcpy_texture(ctx
, dims
,
2317 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2320 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2321 srcAddr
, srcPacking
);
2325 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2328 srcWidth
, srcHeight
, srcDepth
,
2329 srcFormat
, srcType
, srcAddr
,
2331 ctx
->_ImageTransferState
);
2332 const GLfloat
*src
= tempImage
;
2333 GLint img
, row
, col
;
2336 for (img
= 0; img
< srcDepth
; img
++) {
2337 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2338 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2339 + dstYoffset
* dstRowStride
2340 + dstXoffset
* texelBytes
;
2341 for (row
= 0; row
< srcHeight
; row
++) {
2342 GLushort
*dstUS
= (GLushort
*) dstRow
;
2343 for (col
= 0; col
< srcWidth
; col
++) {
2344 GLushort r
, g
, b
, a
;
2346 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2347 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2348 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2349 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2356 dstRow
+= dstRowStride
;
2359 free((void *) tempImage
);
2366 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2368 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2369 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2371 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R_16
||
2372 dstFormat
== MESA_FORMAT_SIGNED_RG_16
||
2373 dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2374 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2376 if (!ctx
->_ImageTransferState
&&
2377 !srcPacking
->SwapBytes
&&
2378 baseInternalFormat
== GL_RGBA
&&
2379 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2380 srcFormat
== GL_RGBA
&&
2381 srcType
== GL_SHORT
) {
2382 /* simple memcpy path */
2383 memcpy_texture(ctx
, dims
,
2384 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2387 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2388 srcAddr
, srcPacking
);
2392 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2395 srcWidth
, srcHeight
, srcDepth
,
2396 srcFormat
, srcType
, srcAddr
,
2398 ctx
->_ImageTransferState
);
2399 const GLfloat
*src
= tempImage
;
2400 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2401 GLint img
, row
, col
;
2406 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2407 * 3 or 4 components/pixel here.
2409 for (img
= 0; img
< srcDepth
; img
++) {
2410 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2411 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2412 + dstYoffset
* dstRowStride
2413 + dstXoffset
* texelBytes
;
2414 for (row
= 0; row
< srcHeight
; row
++) {
2415 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2416 for (col
= 0; col
< srcWidth
; col
++) {
2418 for (c
= 0; c
< comps
; c
++) {
2420 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2421 dstRowS
[col
* comps
+ c
] = p
;
2424 dstRow
+= dstRowStride
;
2425 src
+= 4 * srcWidth
;
2428 free((void *) tempImage
);
2435 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2437 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2438 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2440 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2441 ASSERT(texelBytes
== 1);
2443 if (!ctx
->_ImageTransferState
&&
2444 !srcPacking
->SwapBytes
&&
2445 baseInternalFormat
== GL_RGB
&&
2446 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2447 /* simple memcpy path */
2448 memcpy_texture(ctx
, dims
,
2449 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2452 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2453 srcAddr
, srcPacking
);
2457 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2460 srcWidth
, srcHeight
, srcDepth
,
2461 srcFormat
, srcType
, srcAddr
,
2463 const GLchan
*src
= tempImage
;
2464 GLint img
, row
, col
;
2467 for (img
= 0; img
< srcDepth
; img
++) {
2468 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2469 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2470 + dstYoffset
* dstRowStride
2471 + dstXoffset
* texelBytes
;
2472 for (row
= 0; row
< srcHeight
; row
++) {
2473 for (col
= 0; col
< srcWidth
; col
++) {
2474 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2475 CHAN_TO_UBYTE(src
[GCOMP
]),
2476 CHAN_TO_UBYTE(src
[BCOMP
]) );
2479 dstRow
+= dstRowStride
;
2482 free((void *) tempImage
);
2489 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2492 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2494 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2495 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2497 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2498 dstFormat
== MESA_FORMAT_L8
||
2499 dstFormat
== MESA_FORMAT_I8
||
2500 dstFormat
== MESA_FORMAT_R8
);
2501 ASSERT(texelBytes
== 1);
2503 if (!ctx
->_ImageTransferState
&&
2504 !srcPacking
->SwapBytes
&&
2505 baseInternalFormat
== srcFormat
&&
2506 srcType
== GL_UNSIGNED_BYTE
) {
2507 /* simple memcpy path */
2508 memcpy_texture(ctx
, dims
,
2509 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2512 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2513 srcAddr
, srcPacking
);
2515 else if (!ctx
->_ImageTransferState
&&
2516 srcType
== GL_UNSIGNED_BYTE
&&
2517 can_swizzle(baseInternalFormat
) &&
2518 can_swizzle(srcFormat
)) {
2521 /* dstmap - how to swizzle from RGBA to dst format:
2523 if (dstFormat
== MESA_FORMAT_A8
) {
2529 dstmap
[1] = ZERO
; /* ? */
2530 dstmap
[2] = ZERO
; /* ? */
2531 dstmap
[3] = ONE
; /* ? */
2533 _mesa_swizzle_ubyte_image(ctx
, dims
,
2538 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2539 dstRowStride
, dstImageOffsets
,
2540 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2545 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2548 srcWidth
, srcHeight
, srcDepth
,
2549 srcFormat
, srcType
, srcAddr
,
2551 const GLchan
*src
= tempImage
;
2552 GLint img
, row
, col
;
2555 for (img
= 0; img
< srcDepth
; img
++) {
2556 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2557 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2558 + dstYoffset
* dstRowStride
2559 + dstXoffset
* texelBytes
;
2560 for (row
= 0; row
< srcHeight
; row
++) {
2561 for (col
= 0; col
< srcWidth
; col
++) {
2562 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2564 dstRow
+= dstRowStride
;
2568 free((void *) tempImage
);
2576 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2578 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2580 (void) dims
; (void) baseInternalFormat
;
2581 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2582 ASSERT(texelBytes
== 1);
2583 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2585 if (!ctx
->_ImageTransferState
&&
2586 !srcPacking
->SwapBytes
&&
2587 srcFormat
== GL_COLOR_INDEX
&&
2588 srcType
== GL_UNSIGNED_BYTE
) {
2589 /* simple memcpy path */
2590 memcpy_texture(ctx
, dims
,
2591 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2594 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2595 srcAddr
, srcPacking
);
2600 for (img
= 0; img
< srcDepth
; img
++) {
2601 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2602 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2603 + dstYoffset
* dstRowStride
2604 + dstXoffset
* texelBytes
;
2605 for (row
= 0; row
< srcHeight
; row
++) {
2606 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2607 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2608 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2609 srcType
, src
, srcPacking
,
2610 ctx
->_ImageTransferState
);
2611 dstRow
+= dstRowStride
;
2620 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2623 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2625 const GLboolean littleEndian
= _mesa_little_endian();
2626 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2628 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2630 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2631 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2632 ASSERT(texelBytes
== 2);
2633 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2634 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2635 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2636 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2637 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2639 /* always just memcpy since no pixel transfer ops apply */
2640 memcpy_texture(ctx
, dims
,
2641 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2644 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2645 srcAddr
, srcPacking
);
2647 /* Check if we need byte swapping */
2648 /* XXX the logic here _might_ be wrong */
2649 if (srcPacking
->SwapBytes
^
2650 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2651 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2654 for (img
= 0; img
< srcDepth
; img
++) {
2655 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2656 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2657 + dstYoffset
* dstRowStride
2658 + dstXoffset
* texelBytes
;
2659 for (row
= 0; row
< srcHeight
; row
++) {
2660 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2661 dstRow
+= dstRowStride
;
2669 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2671 const GLboolean littleEndian
= _mesa_little_endian();
2672 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2674 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2675 ASSERT(texelBytes
== 2);
2676 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2677 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2678 (srcFormat
== GL_DUDV_ATI
));
2679 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2681 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2683 /* simple memcpy path */
2684 memcpy_texture(ctx
, dims
,
2685 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2688 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2689 srcAddr
, srcPacking
);
2691 else if (srcType
== GL_BYTE
) {
2694 /* dstmap - how to swizzle from RGBA to dst format:
2704 dstmap
[2] = ZERO
; /* ? */
2705 dstmap
[3] = ONE
; /* ? */
2707 _mesa_swizzle_ubyte_image(ctx
, dims
,
2708 GL_LUMINANCE_ALPHA
, /* hack */
2709 GL_UNSIGNED_BYTE
, /* hack */
2710 GL_LUMINANCE_ALPHA
, /* hack */
2712 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2713 dstRowStride
, dstImageOffsets
,
2714 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2718 /* general path - note this is defined for 2d textures only */
2719 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2720 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2721 srcFormat
, srcType
);
2722 GLbyte
*tempImage
, *dst
, *src
;
2725 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2726 * components
* sizeof(GLbyte
));
2730 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2731 srcWidth
, srcHeight
,
2736 for (row
= 0; row
< srcHeight
; row
++) {
2737 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2738 dst
, srcFormat
, srcType
, src
,
2740 dst
+= srcWidth
* components
;
2745 dst
= (GLbyte
*) dstAddr
2746 + dstYoffset
* dstRowStride
2747 + dstXoffset
* texelBytes
;
2748 for (row
= 0; row
< srcHeight
; row
++) {
2749 memcpy(dst
, src
, srcWidth
* texelBytes
);
2750 dst
+= dstRowStride
;
2751 src
+= srcWidth
* texelBytes
;
2753 free((void *) tempImage
);
2760 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2763 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2765 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2766 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2768 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2769 ASSERT(texelBytes
== 1);
2771 /* XXX look at adding optimized paths */
2774 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2777 srcWidth
, srcHeight
, srcDepth
,
2778 srcFormat
, srcType
, srcAddr
,
2780 ctx
->_ImageTransferState
);
2781 const GLfloat
*srcRow
= tempImage
;
2782 GLint img
, row
, col
;
2785 for (img
= 0; img
< srcDepth
; img
++) {
2786 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2787 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2788 + dstYoffset
* dstRowStride
2789 + dstXoffset
* texelBytes
;
2790 for (row
= 0; row
< srcHeight
; row
++) {
2791 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2792 for (col
= 0; col
< srcWidth
; col
++) {
2793 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2795 dstRow
+= dstRowStride
;
2798 free((void *) tempImage
);
2805 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2808 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2810 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2811 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2813 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2814 ASSERT(texelBytes
== 1);
2816 /* XXX look at adding optimized paths */
2819 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2822 srcWidth
, srcHeight
, srcDepth
,
2823 srcFormat
, srcType
, srcAddr
,
2825 ctx
->_ImageTransferState
);
2826 const GLfloat
*srcRow
= tempImage
;
2827 GLint img
, row
, col
;
2830 for (img
= 0; img
< srcDepth
; img
++) {
2831 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2832 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2833 + dstYoffset
* dstRowStride
2834 + dstXoffset
* texelBytes
;
2835 for (row
= 0; row
< srcHeight
; row
++) {
2836 GLushort
*dstUS
= (GLushort
*) dstRow
;
2837 for (col
= 0; col
< srcWidth
; col
++) {
2838 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2839 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2841 dstRow
+= dstRowStride
;
2844 free((void *) tempImage
);
2851 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2854 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2856 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2857 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2859 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2860 ASSERT(texelBytes
== 4);
2864 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2867 srcWidth
, srcHeight
, srcDepth
,
2868 srcFormat
, srcType
, srcAddr
,
2870 ctx
->_ImageTransferState
);
2871 const GLfloat
*srcRow
= tempImage
;
2872 GLint img
, row
, col
;
2875 for (img
= 0; img
< srcDepth
; img
++) {
2876 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2877 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2878 + dstYoffset
* dstRowStride
2879 + dstXoffset
* texelBytes
;
2880 for (row
= 0; row
< srcHeight
; row
++) {
2881 GLuint
*dstUI
= (GLuint
*) dstRow
;
2882 for (col
= 0; col
< srcWidth
; col
++) {
2883 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2884 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2885 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2889 dstRow
+= dstRowStride
;
2892 free((void *) tempImage
);
2900 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2901 * MESA_FORMAT_SIGNED_RGBA8888_REV
2904 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2906 const GLboolean littleEndian
= _mesa_little_endian();
2907 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2908 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2910 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2911 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2912 ASSERT(texelBytes
== 4);
2914 if (!ctx
->_ImageTransferState
&&
2915 !srcPacking
->SwapBytes
&&
2916 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2917 baseInternalFormat
== GL_RGBA
&&
2918 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2919 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2920 /* simple memcpy path */
2921 memcpy_texture(ctx
, dims
,
2922 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2925 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2926 srcAddr
, srcPacking
);
2928 else if (!ctx
->_ImageTransferState
&&
2929 !srcPacking
->SwapBytes
&&
2930 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2931 baseInternalFormat
== GL_RGBA
&&
2932 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2933 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2934 /* simple memcpy path */
2935 memcpy_texture(ctx
, dims
,
2936 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2939 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2940 srcAddr
, srcPacking
);
2942 else if (!ctx
->_ImageTransferState
&&
2943 (srcType
== GL_BYTE
) &&
2944 can_swizzle(baseInternalFormat
) &&
2945 can_swizzle(srcFormat
)) {
2949 /* dstmap - how to swizzle from RGBA to dst format:
2951 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2952 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2965 _mesa_swizzle_ubyte_image(ctx
, dims
,
2970 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2971 dstRowStride
, dstImageOffsets
,
2972 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2977 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2980 srcWidth
, srcHeight
, srcDepth
,
2981 srcFormat
, srcType
, srcAddr
,
2983 ctx
->_ImageTransferState
);
2984 const GLfloat
*srcRow
= tempImage
;
2985 GLint img
, row
, col
;
2988 for (img
= 0; img
< srcDepth
; img
++) {
2989 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2990 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2991 + dstYoffset
* dstRowStride
2992 + dstXoffset
* texelBytes
;
2993 for (row
= 0; row
< srcHeight
; row
++) {
2994 GLuint
*dstUI
= (GLuint
*) dstRow
;
2995 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2996 for (col
= 0; col
< srcWidth
; col
++) {
2997 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2998 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2999 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3000 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3005 for (col
= 0; col
< srcWidth
; col
++) {
3006 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3007 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3008 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3009 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3013 dstRow
+= dstRowStride
;
3016 free((void *) tempImage
);
3023 * Store a combined depth/stencil texture image.
3026 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3028 const GLuint depthScale
= 0xffffff;
3029 const GLint srcRowStride
3030 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3034 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3035 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
3036 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3038 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3039 ctx
->Pixel
.DepthBias
== 0.0f
&&
3040 !srcPacking
->SwapBytes
) {
3042 memcpy_texture(ctx
, dims
,
3043 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3046 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3047 srcAddr
, srcPacking
);
3049 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
3050 /* In case we only upload depth we need to preserve the stencil */
3051 for (img
= 0; img
< srcDepth
; img
++) {
3052 GLuint
*dstRow
= (GLuint
*) dstAddr
3053 + dstImageOffsets
[dstZoffset
+ img
]
3054 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3057 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3058 srcWidth
, srcHeight
,
3061 for (row
= 0; row
< srcHeight
; row
++) {
3062 GLuint depth
[MAX_WIDTH
];
3063 GLubyte stencil
[MAX_WIDTH
];
3065 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3067 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3068 keepstencil
= GL_TRUE
;
3070 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3071 keepdepth
= GL_TRUE
;
3074 if (keepdepth
== GL_FALSE
)
3075 /* the 24 depth bits will be in the low position: */
3076 _mesa_unpack_depth_span(ctx
, srcWidth
,
3077 GL_UNSIGNED_INT
, /* dst type */
3078 keepstencil
? depth
: dstRow
, /* dst addr */
3080 srcType
, src
, srcPacking
);
3082 if (keepstencil
== GL_FALSE
)
3083 /* get the 8-bit stencil values */
3084 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3085 GL_UNSIGNED_BYTE
, /* dst type */
3086 stencil
, /* dst addr */
3087 srcType
, src
, srcPacking
,
3088 ctx
->_ImageTransferState
);
3090 for (i
= 0; i
< srcWidth
; i
++) {
3092 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3094 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3097 src
+= srcRowStride
;
3098 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3107 * Store a combined depth/stencil texture image.
3110 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3112 const GLuint depthScale
= 0xffffff;
3113 const GLint srcRowStride
3114 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3118 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3119 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3120 srcFormat
== GL_DEPTH_COMPONENT
||
3121 srcFormat
== GL_STENCIL_INDEX
);
3122 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3123 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3125 for (img
= 0; img
< srcDepth
; img
++) {
3126 GLuint
*dstRow
= (GLuint
*) dstAddr
3127 + dstImageOffsets
[dstZoffset
+ img
]
3128 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3131 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3132 srcWidth
, srcHeight
,
3135 for (row
= 0; row
< srcHeight
; row
++) {
3136 GLuint depth
[MAX_WIDTH
];
3137 GLubyte stencil
[MAX_WIDTH
];
3139 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3141 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3142 keepstencil
= GL_TRUE
;
3144 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3145 keepdepth
= GL_TRUE
;
3148 if (keepdepth
== GL_FALSE
)
3149 /* the 24 depth bits will be in the low position: */
3150 _mesa_unpack_depth_span(ctx
, srcWidth
,
3151 GL_UNSIGNED_INT
, /* dst type */
3152 keepstencil
? depth
: dstRow
, /* dst addr */
3154 srcType
, src
, srcPacking
);
3156 if (keepstencil
== GL_FALSE
)
3157 /* get the 8-bit stencil values */
3158 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3159 GL_UNSIGNED_BYTE
, /* dst type */
3160 stencil
, /* dst addr */
3161 srcType
, src
, srcPacking
,
3162 ctx
->_ImageTransferState
);
3164 /* merge stencil values into depth values */
3165 for (i
= 0; i
< srcWidth
; i
++) {
3167 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3169 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3172 src
+= srcRowStride
;
3173 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3181 * Store simple 8-bit/value stencil texture data.
3184 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3186 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3187 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3189 if (!ctx
->_ImageTransferState
&&
3190 !srcPacking
->SwapBytes
&&
3191 baseInternalFormat
== srcFormat
&&
3192 srcType
== GL_UNSIGNED_BYTE
) {
3193 /* simple memcpy path */
3194 memcpy_texture(ctx
, dims
,
3195 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3198 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3199 srcAddr
, srcPacking
);
3202 const GLint srcRowStride
3203 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3207 for (img
= 0; img
< srcDepth
; img
++) {
3208 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3209 + dstImageOffsets
[dstZoffset
+ img
]
3210 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3213 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3214 srcWidth
, srcHeight
,
3217 for (row
= 0; row
< srcHeight
; row
++) {
3218 GLubyte stencil
[MAX_WIDTH
];
3221 /* get the 8-bit stencil values */
3222 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3223 GL_UNSIGNED_BYTE
, /* dst type */
3224 stencil
, /* dst addr */
3225 srcType
, src
, srcPacking
,
3226 ctx
->_ImageTransferState
);
3227 /* merge stencil values into depth values */
3228 for (i
= 0; i
< srcWidth
; i
++)
3229 dstRow
[i
] = stencil
[i
];
3231 src
+= srcRowStride
;
3232 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3243 * Store an image in any of the formats:
3244 * _mesa_texformat_rgba_float32
3245 * _mesa_texformat_rgb_float32
3246 * _mesa_texformat_alpha_float32
3247 * _mesa_texformat_luminance_float32
3248 * _mesa_texformat_luminance_alpha_float32
3249 * _mesa_texformat_intensity_float32
3252 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3254 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3255 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3256 const GLint components
= _mesa_components_in_format(baseFormat
);
3258 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3259 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3260 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3261 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3262 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3263 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3264 ASSERT(baseInternalFormat
== GL_RGBA
||
3265 baseInternalFormat
== GL_RGB
||
3266 baseInternalFormat
== GL_ALPHA
||
3267 baseInternalFormat
== GL_LUMINANCE
||
3268 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3269 baseInternalFormat
== GL_INTENSITY
);
3270 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3272 if (!ctx
->_ImageTransferState
&&
3273 !srcPacking
->SwapBytes
&&
3274 baseInternalFormat
== srcFormat
&&
3275 srcType
== GL_FLOAT
) {
3276 /* simple memcpy path */
3277 memcpy_texture(ctx
, dims
,
3278 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3281 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3282 srcAddr
, srcPacking
);
3286 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3289 srcWidth
, srcHeight
, srcDepth
,
3290 srcFormat
, srcType
, srcAddr
,
3292 ctx
->_ImageTransferState
);
3293 const GLfloat
*srcRow
= tempImage
;
3298 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3299 for (img
= 0; img
< srcDepth
; img
++) {
3300 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3301 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3302 + dstYoffset
* dstRowStride
3303 + dstXoffset
* texelBytes
;
3304 for (row
= 0; row
< srcHeight
; row
++) {
3305 memcpy(dstRow
, srcRow
, bytesPerRow
);
3306 dstRow
+= dstRowStride
;
3307 srcRow
+= srcWidth
* components
;
3311 free((void *) tempImage
);
3319 * As above, but store 16-bit floats.
3322 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3324 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3325 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3326 const GLint components
= _mesa_components_in_format(baseFormat
);
3328 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3329 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3330 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3331 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3332 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3333 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3334 ASSERT(baseInternalFormat
== GL_RGBA
||
3335 baseInternalFormat
== GL_RGB
||
3336 baseInternalFormat
== GL_ALPHA
||
3337 baseInternalFormat
== GL_LUMINANCE
||
3338 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3339 baseInternalFormat
== GL_INTENSITY
);
3340 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3342 if (!ctx
->_ImageTransferState
&&
3343 !srcPacking
->SwapBytes
&&
3344 baseInternalFormat
== srcFormat
&&
3345 srcType
== GL_HALF_FLOAT_ARB
) {
3346 /* simple memcpy path */
3347 memcpy_texture(ctx
, dims
,
3348 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3351 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3352 srcAddr
, srcPacking
);
3356 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3359 srcWidth
, srcHeight
, srcDepth
,
3360 srcFormat
, srcType
, srcAddr
,
3362 ctx
->_ImageTransferState
);
3363 const GLfloat
*src
= tempImage
;
3367 for (img
= 0; img
< srcDepth
; img
++) {
3368 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3369 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3370 + dstYoffset
* dstRowStride
3371 + dstXoffset
* texelBytes
;
3372 for (row
= 0; row
< srcHeight
; row
++) {
3373 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3375 for (i
= 0; i
< srcWidth
* components
; i
++) {
3376 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3378 dstRow
+= dstRowStride
;
3379 src
+= srcWidth
* components
;
3383 free((void *) tempImage
);
3389 /* non-normalized, signed int8 */
3391 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3393 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3394 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3395 const GLint components
= _mesa_components_in_format(baseFormat
);
3397 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3398 ASSERT(baseInternalFormat
== GL_RGBA
||
3399 baseInternalFormat
== GL_RGB
||
3400 baseInternalFormat
== GL_ALPHA
||
3401 baseInternalFormat
== GL_LUMINANCE
||
3402 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3403 baseInternalFormat
== GL_INTENSITY
);
3404 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3406 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3407 * to integer formats.
3409 if (!srcPacking
->SwapBytes
&&
3410 baseInternalFormat
== srcFormat
&&
3411 srcType
== GL_BYTE
) {
3412 /* simple memcpy path */
3413 memcpy_texture(ctx
, dims
,
3414 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3417 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3418 srcAddr
, srcPacking
);
3422 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3425 srcWidth
, srcHeight
, srcDepth
,
3426 srcFormat
, srcType
, srcAddr
,
3428 const GLfloat
*src
= tempImage
;
3432 for (img
= 0; img
< srcDepth
; img
++) {
3433 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3434 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3435 + dstYoffset
* dstRowStride
3436 + dstXoffset
* texelBytes
;
3437 for (row
= 0; row
< srcHeight
; row
++) {
3438 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3440 for (i
= 0; i
< srcWidth
* components
; i
++) {
3441 dstTexel
[i
] = (GLbyte
) src
[i
];
3443 dstRow
+= dstRowStride
;
3444 src
+= srcWidth
* components
;
3448 free((void *) tempImage
);
3454 /* non-normalized, signed int16 */
3456 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3458 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3459 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3460 const GLint components
= _mesa_components_in_format(baseFormat
);
3462 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3463 ASSERT(baseInternalFormat
== GL_RGBA
||
3464 baseInternalFormat
== GL_RGB
||
3465 baseInternalFormat
== GL_ALPHA
||
3466 baseInternalFormat
== GL_LUMINANCE
||
3467 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3468 baseInternalFormat
== GL_INTENSITY
);
3469 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3471 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3472 * to integer formats.
3474 if (!srcPacking
->SwapBytes
&&
3475 baseInternalFormat
== srcFormat
&&
3476 srcType
== GL_SHORT
) {
3477 /* simple memcpy path */
3478 memcpy_texture(ctx
, dims
,
3479 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3482 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3483 srcAddr
, srcPacking
);
3487 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3490 srcWidth
, srcHeight
, srcDepth
,
3491 srcFormat
, srcType
, srcAddr
,
3493 const GLfloat
*src
= tempImage
;
3497 for (img
= 0; img
< srcDepth
; img
++) {
3498 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3499 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3500 + dstYoffset
* dstRowStride
3501 + dstXoffset
* texelBytes
;
3502 for (row
= 0; row
< srcHeight
; row
++) {
3503 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3505 for (i
= 0; i
< srcWidth
* components
; i
++) {
3506 dstTexel
[i
] = (GLint
) src
[i
];
3508 dstRow
+= dstRowStride
;
3509 src
+= srcWidth
* components
;
3513 free((void *) tempImage
);
3519 /* non-normalized, signed int32 */
3521 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3523 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3524 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3525 const GLint components
= _mesa_components_in_format(baseFormat
);
3527 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3528 ASSERT(baseInternalFormat
== GL_RGBA
||
3529 baseInternalFormat
== GL_RGB
||
3530 baseInternalFormat
== GL_ALPHA
||
3531 baseInternalFormat
== GL_LUMINANCE
||
3532 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3533 baseInternalFormat
== GL_INTENSITY
);
3534 ASSERT(texelBytes
== components
* sizeof(GLint
));
3536 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3537 * to integer formats.
3539 if (!srcPacking
->SwapBytes
&&
3540 baseInternalFormat
== srcFormat
&&
3541 srcType
== GL_INT
) {
3542 /* simple memcpy path */
3543 memcpy_texture(ctx
, dims
,
3544 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3547 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3548 srcAddr
, srcPacking
);
3552 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3555 srcWidth
, srcHeight
, srcDepth
,
3556 srcFormat
, srcType
, srcAddr
,
3558 const GLfloat
*src
= tempImage
;
3562 for (img
= 0; img
< srcDepth
; img
++) {
3563 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3564 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3565 + dstYoffset
* dstRowStride
3566 + dstXoffset
* texelBytes
;
3567 for (row
= 0; row
< srcHeight
; row
++) {
3568 GLint
*dstTexel
= (GLint
*) dstRow
;
3570 for (i
= 0; i
< srcWidth
* components
; i
++) {
3571 dstTexel
[i
] = (GLint
) src
[i
];
3573 dstRow
+= dstRowStride
;
3574 src
+= srcWidth
* components
;
3578 free((void *) tempImage
);
3584 /* non-normalized, unsigned int8 */
3586 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3588 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3589 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3590 const GLint components
= _mesa_components_in_format(baseFormat
);
3592 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3593 ASSERT(baseInternalFormat
== GL_RGBA
||
3594 baseInternalFormat
== GL_RGB
||
3595 baseInternalFormat
== GL_ALPHA
||
3596 baseInternalFormat
== GL_LUMINANCE
||
3597 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3598 baseInternalFormat
== GL_INTENSITY
);
3599 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3601 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3602 * to integer formats.
3604 if (!srcPacking
->SwapBytes
&&
3605 baseInternalFormat
== srcFormat
&&
3606 srcType
== GL_UNSIGNED_BYTE
) {
3607 /* simple memcpy path */
3608 memcpy_texture(ctx
, dims
,
3609 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3612 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3613 srcAddr
, srcPacking
);
3617 const GLuint
*tempImage
=
3618 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3619 srcWidth
, srcHeight
, srcDepth
,
3620 srcFormat
, srcType
, srcAddr
, srcPacking
);
3621 const GLuint
*src
= tempImage
;
3625 for (img
= 0; img
< srcDepth
; img
++) {
3626 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3627 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3628 + dstYoffset
* dstRowStride
3629 + dstXoffset
* texelBytes
;
3630 for (row
= 0; row
< srcHeight
; row
++) {
3631 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3633 for (i
= 0; i
< srcWidth
* components
; i
++) {
3634 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3636 dstRow
+= dstRowStride
;
3637 src
+= srcWidth
* components
;
3641 free((void *) tempImage
);
3647 /* non-normalized, unsigned int16 */
3649 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3651 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3652 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3653 const GLint components
= _mesa_components_in_format(baseFormat
);
3655 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3656 ASSERT(baseInternalFormat
== GL_RGBA
||
3657 baseInternalFormat
== GL_RGB
||
3658 baseInternalFormat
== GL_ALPHA
||
3659 baseInternalFormat
== GL_LUMINANCE
||
3660 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3661 baseInternalFormat
== GL_INTENSITY
);
3662 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3664 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3665 * to integer formats.
3667 if (!srcPacking
->SwapBytes
&&
3668 baseInternalFormat
== srcFormat
&&
3669 srcType
== GL_UNSIGNED_SHORT
) {
3670 /* simple memcpy path */
3671 memcpy_texture(ctx
, dims
,
3672 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3675 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3676 srcAddr
, srcPacking
);
3680 const GLuint
*tempImage
=
3681 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3682 srcWidth
, srcHeight
, srcDepth
,
3683 srcFormat
, srcType
, srcAddr
, srcPacking
);
3684 const GLuint
*src
= tempImage
;
3688 for (img
= 0; img
< srcDepth
; img
++) {
3689 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3690 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3691 + dstYoffset
* dstRowStride
3692 + dstXoffset
* texelBytes
;
3693 for (row
= 0; row
< srcHeight
; row
++) {
3694 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3696 for (i
= 0; i
< srcWidth
* components
; i
++) {
3697 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3699 dstRow
+= dstRowStride
;
3700 src
+= srcWidth
* components
;
3704 free((void *) tempImage
);
3710 /* non-normalized, unsigned int32 */
3712 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3714 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3715 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3716 const GLint components
= _mesa_components_in_format(baseFormat
);
3718 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3719 ASSERT(baseInternalFormat
== GL_RGBA
||
3720 baseInternalFormat
== GL_RGB
||
3721 baseInternalFormat
== GL_ALPHA
||
3722 baseInternalFormat
== GL_LUMINANCE
||
3723 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3724 baseInternalFormat
== GL_INTENSITY
);
3725 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3727 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3728 * to integer formats.
3730 if (!srcPacking
->SwapBytes
&&
3731 baseInternalFormat
== srcFormat
&&
3732 srcType
== GL_UNSIGNED_INT
) {
3733 /* simple memcpy path */
3734 memcpy_texture(ctx
, dims
,
3735 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3738 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3739 srcAddr
, srcPacking
);
3743 const GLuint
*tempImage
=
3744 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3745 srcWidth
, srcHeight
, srcDepth
,
3746 srcFormat
, srcType
, srcAddr
, srcPacking
);
3747 const GLuint
*src
= tempImage
;
3751 for (img
= 0; img
< srcDepth
; img
++) {
3752 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3753 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3754 + dstYoffset
* dstRowStride
3755 + dstXoffset
* texelBytes
;
3756 for (row
= 0; row
< srcHeight
; row
++) {
3757 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3759 for (i
= 0; i
< srcWidth
* components
; i
++) {
3760 dstTexel
[i
] = src
[i
];
3762 dstRow
+= dstRowStride
;
3763 src
+= srcWidth
* components
;
3767 free((void *) tempImage
);
3775 #if FEATURE_EXT_texture_sRGB
3777 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3779 gl_format newDstFormat
;
3782 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3784 /* reuse normal rgb texstore code */
3785 newDstFormat
= MESA_FORMAT_RGB888
;
3787 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3788 newDstFormat
, dstAddr
,
3789 dstXoffset
, dstYoffset
, dstZoffset
,
3790 dstRowStride
, dstImageOffsets
,
3791 srcWidth
, srcHeight
, srcDepth
,
3793 srcAddr
, srcPacking
);
3799 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3801 gl_format newDstFormat
;
3804 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3806 /* reuse normal rgba texstore code */
3807 newDstFormat
= MESA_FORMAT_RGBA8888
;
3808 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3809 newDstFormat
, dstAddr
,
3810 dstXoffset
, dstYoffset
, dstZoffset
,
3811 dstRowStride
, dstImageOffsets
,
3812 srcWidth
, srcHeight
, srcDepth
,
3814 srcAddr
, srcPacking
);
3820 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3822 gl_format newDstFormat
;
3825 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3827 /* reuse normal rgba texstore code */
3828 newDstFormat
= MESA_FORMAT_ARGB8888
;
3830 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3831 newDstFormat
, dstAddr
,
3832 dstXoffset
, dstYoffset
, dstZoffset
,
3833 dstRowStride
, dstImageOffsets
,
3834 srcWidth
, srcHeight
, srcDepth
,
3836 srcAddr
, srcPacking
);
3842 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3844 gl_format newDstFormat
;
3847 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3849 newDstFormat
= MESA_FORMAT_L8
;
3851 /* _mesa_textore_a8 handles luminance8 too */
3852 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3853 newDstFormat
, dstAddr
,
3854 dstXoffset
, dstYoffset
, dstZoffset
,
3855 dstRowStride
, dstImageOffsets
,
3856 srcWidth
, srcHeight
, srcDepth
,
3858 srcAddr
, srcPacking
);
3864 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3866 gl_format newDstFormat
;
3869 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3871 /* reuse normal luminance/alpha texstore code */
3872 newDstFormat
= MESA_FORMAT_AL88
;
3874 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3875 newDstFormat
, dstAddr
,
3876 dstXoffset
, dstYoffset
, dstZoffset
,
3877 dstRowStride
, dstImageOffsets
,
3878 srcWidth
, srcHeight
, srcDepth
,
3880 srcAddr
, srcPacking
);
3886 /* these are used only in texstore_funcs[] below */
3887 #define _mesa_texstore_srgb8 NULL
3888 #define _mesa_texstore_srgba8 NULL
3889 #define _mesa_texstore_sargb8 NULL
3890 #define _mesa_texstore_sl8 NULL
3891 #define _mesa_texstore_sla8 NULL
3893 #endif /* FEATURE_EXT_texture_sRGB */
3899 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
3900 * XXX this is somewhat temporary.
3902 static const struct {
3904 StoreTexImageFunc Store
;
3906 texstore_funcs
[MESA_FORMAT_COUNT
] =
3908 { MESA_FORMAT_NONE
, NULL
},
3909 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
3910 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
3911 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
3912 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
3913 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
3914 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
3915 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
3916 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
3917 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
3918 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
3919 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
3920 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
3921 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
3922 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
3923 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
3924 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
3925 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
3926 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
3927 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
3928 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
3929 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
3930 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
3931 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
3932 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
3933 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
3934 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
3935 { MESA_FORMAT_R8
, _mesa_texstore_a8
},
3936 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
3937 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
3938 { MESA_FORMAT_R16
, _mesa_texstore_r16
},
3939 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
3940 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
3941 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
3942 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
3943 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3944 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
3945 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
3946 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3947 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
3948 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3949 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3950 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3951 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3952 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3953 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3954 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3955 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3956 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3957 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3958 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3959 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3960 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3961 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3962 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3963 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3964 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3965 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3966 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3967 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3968 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3969 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3970 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3971 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3972 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3973 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3974 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3976 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
3977 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
3978 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
3979 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
3980 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
3981 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
3983 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3985 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
3986 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
3987 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
3989 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3990 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3992 { MESA_FORMAT_SIGNED_R_16
, _mesa_texstore_signed_rgba_16
},
3993 { MESA_FORMAT_SIGNED_RG_16
, _mesa_texstore_signed_rgba_16
},
3994 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
3995 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
3996 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
}
4001 _mesa_texstore_null(TEXSTORE_PARAMS
)
4003 (void) ctx
; (void) dims
;
4004 (void) baseInternalFormat
;
4007 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4008 (void) dstRowStride
; (void) dstImageOffsets
;
4009 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4010 (void) srcFormat
; (void) srcType
;
4014 /* should never happen */
4015 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4021 * Return the StoreTexImageFunc pointer to store an image in the given format.
4023 static StoreTexImageFunc
4024 _mesa_get_texstore_func(gl_format format
)
4028 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4029 ASSERT(texstore_funcs
[i
].Name
== i
);
4032 ASSERT(texstore_funcs
[format
].Name
== format
);
4034 if (texstore_funcs
[format
].Store
)
4035 return texstore_funcs
[format
].Store
;
4037 return _mesa_texstore_null
;
4042 * Store user data into texture memory.
4043 * Called via glTex[Sub]Image1/2/3D()
4046 _mesa_texstore(TEXSTORE_PARAMS
)
4048 StoreTexImageFunc storeImage
;
4051 storeImage
= _mesa_get_texstore_func(dstFormat
);
4053 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4054 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4055 dstRowStride
, dstImageOffsets
,
4056 srcWidth
, srcHeight
, srcDepth
,
4057 srcFormat
, srcType
, srcAddr
, srcPacking
);
4063 * Check if an unpack PBO is active prior to fetching a texture image.
4064 * If so, do bounds checking and map the buffer into main memory.
4065 * Any errors detected will be recorded.
4066 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4069 _mesa_validate_pbo_teximage(struct gl_context
*ctx
, GLuint dimensions
,
4070 GLsizei width
, GLsizei height
, GLsizei depth
,
4071 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4072 const struct gl_pixelstore_attrib
*unpack
,
4073 const char *funcName
)
4077 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
4081 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
4082 format
, type
, pixels
)) {
4083 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4087 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4088 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
4090 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped)");
4094 return ADD_POINTERS(buf
, pixels
);
4099 * Check if an unpack PBO is active prior to fetching a compressed texture
4101 * If so, do bounds checking and map the buffer into main memory.
4102 * Any errors detected will be recorded.
4103 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4106 _mesa_validate_pbo_compressed_teximage(struct gl_context
*ctx
,
4107 GLsizei imageSize
, const GLvoid
*pixels
,
4108 const struct gl_pixelstore_attrib
*packing
,
4109 const char *funcName
)
4113 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
4114 /* not using a PBO - return pointer unchanged */
4117 if ((const GLubyte
*) pixels
+ imageSize
>
4118 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
4119 /* out of bounds read! */
4120 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4124 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4125 GL_READ_ONLY_ARB
, packing
->BufferObj
);
4127 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
4131 return ADD_POINTERS(buf
, pixels
);
4136 * This function must be called after either of the validate_pbo_*_teximage()
4137 * functions. It unmaps the PBO buffer if it was mapped earlier.
4140 _mesa_unmap_teximage_pbo(struct gl_context
*ctx
,
4141 const struct gl_pixelstore_attrib
*unpack
)
4143 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
4144 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4150 /** Return texture size in bytes */
4152 texture_size(const struct gl_texture_image
*texImage
)
4154 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4155 texImage
->Height
, texImage
->Depth
);
4160 /** Return row stride in bytes */
4162 texture_row_stride(const struct gl_texture_image
*texImage
)
4164 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4172 * This is the software fallback for Driver.TexImage1D()
4173 * and Driver.CopyTexImage1D().
4174 * \sa _mesa_store_teximage2d()
4177 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4178 GLint internalFormat
,
4179 GLint width
, GLint border
,
4180 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4181 const struct gl_pixelstore_attrib
*packing
,
4182 struct gl_texture_object
*texObj
,
4183 struct gl_texture_image
*texImage
)
4188 /* allocate memory */
4189 sizeInBytes
= texture_size(texImage
);
4190 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4191 if (!texImage
->Data
) {
4192 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4196 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4197 pixels
, packing
, "glTexImage1D");
4199 /* Note: we check for a NULL image pointer here, _after_ we allocated
4200 * memory for the texture. That's what the GL spec calls for.
4205 const GLint dstRowStride
= 0;
4206 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4207 texImage
->TexFormat
,
4209 0, 0, 0, /* dstX/Y/Zoffset */
4211 texImage
->ImageOffsets
,
4213 format
, type
, pixels
, packing
);
4215 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4219 _mesa_unmap_teximage_pbo(ctx
, packing
);
4224 * This is the software fallback for Driver.TexImage2D()
4225 * and Driver.CopyTexImage2D().
4227 * This function is oriented toward storing images in main memory, rather
4228 * than VRAM. Device driver's can easily plug in their own replacement.
4231 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4232 GLint internalFormat
,
4233 GLint width
, GLint height
, GLint border
,
4234 GLenum format
, GLenum type
, const void *pixels
,
4235 const struct gl_pixelstore_attrib
*packing
,
4236 struct gl_texture_object
*texObj
,
4237 struct gl_texture_image
*texImage
)
4242 /* allocate memory */
4243 sizeInBytes
= texture_size(texImage
);
4244 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4245 if (!texImage
->Data
) {
4246 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4250 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4251 pixels
, packing
, "glTexImage2D");
4253 /* Note: we check for a NULL image pointer here, _after_ we allocated
4254 * memory for the texture. That's what the GL spec calls for.
4259 GLint dstRowStride
= texture_row_stride(texImage
);
4260 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4261 texImage
->TexFormat
,
4263 0, 0, 0, /* dstX/Y/Zoffset */
4265 texImage
->ImageOffsets
,
4267 format
, type
, pixels
, packing
);
4269 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4273 _mesa_unmap_teximage_pbo(ctx
, packing
);
4279 * This is the software fallback for Driver.TexImage3D()
4280 * and Driver.CopyTexImage3D().
4281 * \sa _mesa_store_teximage2d()
4284 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4285 GLint internalFormat
,
4286 GLint width
, GLint height
, GLint depth
, GLint border
,
4287 GLenum format
, GLenum type
, const void *pixels
,
4288 const struct gl_pixelstore_attrib
*packing
,
4289 struct gl_texture_object
*texObj
,
4290 struct gl_texture_image
*texImage
)
4295 /* allocate memory */
4296 sizeInBytes
= texture_size(texImage
);
4297 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4298 if (!texImage
->Data
) {
4299 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4303 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4304 type
, pixels
, packing
, "glTexImage3D");
4306 /* Note: we check for a NULL image pointer here, _after_ we allocated
4307 * memory for the texture. That's what the GL spec calls for.
4312 GLint dstRowStride
= texture_row_stride(texImage
);
4313 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4314 texImage
->TexFormat
,
4316 0, 0, 0, /* dstX/Y/Zoffset */
4318 texImage
->ImageOffsets
,
4319 width
, height
, depth
,
4320 format
, type
, pixels
, packing
);
4322 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4326 _mesa_unmap_teximage_pbo(ctx
, packing
);
4333 * This is the software fallback for Driver.TexSubImage1D()
4334 * and Driver.CopyTexSubImage1D().
4337 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4338 GLint xoffset
, GLint width
,
4339 GLenum format
, GLenum type
, const void *pixels
,
4340 const struct gl_pixelstore_attrib
*packing
,
4341 struct gl_texture_object
*texObj
,
4342 struct gl_texture_image
*texImage
)
4344 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4345 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4346 pixels
, packing
, "glTexSubImage1D");
4351 const GLint dstRowStride
= 0;
4352 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4353 texImage
->TexFormat
,
4355 xoffset
, 0, 0, /* offsets */
4357 texImage
->ImageOffsets
,
4359 format
, type
, pixels
, packing
);
4361 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4365 _mesa_unmap_teximage_pbo(ctx
, packing
);
4371 * This is the software fallback for Driver.TexSubImage2D()
4372 * and Driver.CopyTexSubImage2D().
4375 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4376 GLint xoffset
, GLint yoffset
,
4377 GLint width
, GLint height
,
4378 GLenum format
, GLenum type
, const void *pixels
,
4379 const struct gl_pixelstore_attrib
*packing
,
4380 struct gl_texture_object
*texObj
,
4381 struct gl_texture_image
*texImage
)
4383 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4384 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4385 pixels
, packing
, "glTexSubImage2D");
4390 GLint dstRowStride
= texture_row_stride(texImage
);
4391 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4392 texImage
->TexFormat
,
4394 xoffset
, yoffset
, 0,
4396 texImage
->ImageOffsets
,
4398 format
, type
, pixels
, packing
);
4400 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4404 _mesa_unmap_teximage_pbo(ctx
, packing
);
4409 * This is the software fallback for Driver.TexSubImage3D().
4410 * and Driver.CopyTexSubImage3D().
4413 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4414 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4415 GLint width
, GLint height
, GLint depth
,
4416 GLenum format
, GLenum type
, const void *pixels
,
4417 const struct gl_pixelstore_attrib
*packing
,
4418 struct gl_texture_object
*texObj
,
4419 struct gl_texture_image
*texImage
)
4421 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4422 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4423 type
, pixels
, packing
,
4429 GLint dstRowStride
= texture_row_stride(texImage
);
4430 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4431 texImage
->TexFormat
,
4433 xoffset
, yoffset
, zoffset
,
4435 texImage
->ImageOffsets
,
4436 width
, height
, depth
,
4437 format
, type
, pixels
, packing
);
4439 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4443 _mesa_unmap_teximage_pbo(ctx
, packing
);
4448 * Fallback for Driver.CompressedTexImage1D()
4451 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4452 GLenum target
, GLint level
,
4453 GLint internalFormat
,
4454 GLint width
, GLint border
,
4455 GLsizei imageSize
, const GLvoid
*data
,
4456 struct gl_texture_object
*texObj
,
4457 struct gl_texture_image
*texImage
)
4459 /* this space intentionally left blank */
4461 (void) target
; (void) level
;
4462 (void) internalFormat
;
4463 (void) width
; (void) border
;
4464 (void) imageSize
; (void) data
;
4472 * Fallback for Driver.CompressedTexImage2D()
4475 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4476 GLenum target
, GLint level
,
4477 GLint internalFormat
,
4478 GLint width
, GLint height
, GLint border
,
4479 GLsizei imageSize
, const GLvoid
*data
,
4480 struct gl_texture_object
*texObj
,
4481 struct gl_texture_image
*texImage
)
4483 (void) width
; (void) height
; (void) border
;
4485 /* This is pretty simple, basically just do a memcpy without worrying
4486 * about the usual image unpacking or image transfer operations.
4490 ASSERT(texImage
->Width
> 0);
4491 ASSERT(texImage
->Height
> 0);
4492 ASSERT(texImage
->Depth
== 1);
4493 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4495 /* allocate storage */
4496 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4497 if (!texImage
->Data
) {
4498 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4502 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4504 "glCompressedTexImage2D");
4509 memcpy(texImage
->Data
, data
, imageSize
);
4511 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4517 * Fallback for Driver.CompressedTexImage3D()
4520 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4521 GLenum target
, GLint level
,
4522 GLint internalFormat
,
4523 GLint width
, GLint height
, GLint depth
,
4525 GLsizei imageSize
, const GLvoid
*data
,
4526 struct gl_texture_object
*texObj
,
4527 struct gl_texture_image
*texImage
)
4529 /* this space intentionally left blank */
4531 (void) target
; (void) level
;
4532 (void) internalFormat
;
4533 (void) width
; (void) height
; (void) depth
;
4535 (void) imageSize
; (void) data
;
4543 * Fallback for Driver.CompressedTexSubImage1D()
4546 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4548 GLint xoffset
, GLsizei width
,
4550 GLsizei imageSize
, const GLvoid
*data
,
4551 struct gl_texture_object
*texObj
,
4552 struct gl_texture_image
*texImage
)
4554 /* there are no compressed 1D texture formats yet */
4556 (void) target
; (void) level
;
4557 (void) xoffset
; (void) width
;
4559 (void) imageSize
; (void) data
;
4566 * Fallback for Driver.CompressedTexSubImage2D()
4569 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4571 GLint xoffset
, GLint yoffset
,
4572 GLsizei width
, GLsizei height
,
4574 GLsizei imageSize
, const GLvoid
*data
,
4575 struct gl_texture_object
*texObj
,
4576 struct gl_texture_image
*texImage
)
4578 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4582 const gl_format texFormat
= texImage
->TexFormat
;
4583 const GLint destWidth
= texImage
->Width
;
4586 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4591 /* these should have been caught sooner */
4592 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4593 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4594 ASSERT((xoffset
% bw
) == 0);
4595 ASSERT((yoffset
% bh
) == 0);
4597 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4598 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4600 "glCompressedTexSubImage2D");
4604 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4605 src
= (const GLubyte
*) data
;
4607 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4608 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4609 texFormat
, destWidth
,
4610 (GLubyte
*) texImage
->Data
);
4612 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4613 rows
= height
/ bh
; /* rows in blocks */
4615 /* copy rows of blocks */
4616 for (i
= 0; i
< rows
; i
++) {
4617 memcpy(dest
, src
, bytesPerRow
);
4618 dest
+= destRowStride
;
4619 src
+= srcRowStride
;
4622 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4627 * Fallback for Driver.CompressedTexSubImage3D()
4630 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4632 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4633 GLsizei width
, GLsizei height
, GLsizei depth
,
4635 GLsizei imageSize
, const GLvoid
*data
,
4636 struct gl_texture_object
*texObj
,
4637 struct gl_texture_image
*texImage
)
4639 /* there are no compressed 3D texture formats yet */
4641 (void) target
; (void) level
;
4642 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4643 (void) width
; (void) height
; (void) depth
;
4645 (void) imageSize
; (void) data
;