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 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2044 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2045 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2047 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2048 ASSERT(texelBytes
== 4);
2050 if (!ctx
->_ImageTransferState
&&
2051 !srcPacking
->SwapBytes
&&
2052 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2053 srcFormat
== GL_BGRA
&&
2054 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2055 baseInternalFormat
== GL_RGBA
) {
2056 /* simple memcpy path */
2057 memcpy_texture(ctx
, dims
,
2058 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2061 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2062 srcAddr
, srcPacking
);
2066 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2069 srcWidth
, srcHeight
, srcDepth
,
2070 srcFormat
, srcType
, srcAddr
,
2072 const GLchan
*src
= tempImage
;
2073 GLint img
, row
, col
;
2076 for (img
= 0; img
< srcDepth
; img
++) {
2077 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2078 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2079 + dstYoffset
* dstRowStride
2080 + dstXoffset
* texelBytes
;
2081 if (baseInternalFormat
== GL_RGBA
) {
2082 for (row
= 0; row
< srcHeight
; row
++) {
2083 GLuint
*dstUS
= (GLuint
*) dstRow
;
2084 for (col
= 0; col
< srcWidth
; col
++) {
2085 dstUS
[col
] = PACK_COLOR_2101010( CHAN_TO_UBYTE(src
[ACOMP
]),
2086 CHAN_TO_UBYTE(src
[RCOMP
]),
2087 CHAN_TO_UBYTE(src
[GCOMP
]),
2088 CHAN_TO_UBYTE(src
[BCOMP
]) );
2091 dstRow
+= dstRowStride
;
2093 } else if (baseInternalFormat
== GL_RGB
) {
2094 for (row
= 0; row
< srcHeight
; row
++) {
2095 GLuint
*dstUS
= (GLuint
*) dstRow
;
2096 for (col
= 0; col
< srcWidth
; col
++) {
2097 dstUS
[col
] = PACK_COLOR_2101010( 0xff,
2098 CHAN_TO_UBYTE(src
[RCOMP
]),
2099 CHAN_TO_UBYTE(src
[GCOMP
]),
2100 CHAN_TO_UBYTE(src
[BCOMP
]) );
2103 dstRow
+= dstRowStride
;
2109 free((void *) tempImage
);
2116 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2119 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2121 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2122 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2124 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2125 ASSERT(texelBytes
== 1);
2129 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2132 srcWidth
, srcHeight
, srcDepth
,
2133 srcFormat
, srcType
, srcAddr
,
2135 const GLchan
*src
= tempImage
;
2136 GLint img
, row
, col
;
2139 for (img
= 0; img
< srcDepth
; img
++) {
2140 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2141 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2142 + dstYoffset
* dstRowStride
2143 + dstXoffset
* texelBytes
;
2144 for (row
= 0; row
< srcHeight
; row
++) {
2145 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2146 for (col
= 0; col
< srcWidth
; col
++) {
2147 /* src[0] is luminance, src[1] is alpha */
2148 dstUS
[col
] = PACK_COLOR_44( CHAN_TO_UBYTE(src
[1]),
2149 CHAN_TO_UBYTE(src
[0]) );
2152 dstRow
+= dstRowStride
;
2155 free((void *) tempImage
);
2162 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2165 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2167 const GLboolean littleEndian
= _mesa_little_endian();
2168 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2169 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2171 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2172 dstFormat
== MESA_FORMAT_AL88_REV
||
2173 dstFormat
== MESA_FORMAT_RG88
||
2174 dstFormat
== MESA_FORMAT_RG88_REV
);
2175 ASSERT(texelBytes
== 2);
2177 if (!ctx
->_ImageTransferState
&&
2178 !srcPacking
->SwapBytes
&&
2179 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
2180 baseInternalFormat
== srcFormat
&&
2181 srcType
== GL_UNSIGNED_BYTE
&&
2183 /* simple memcpy path */
2184 memcpy_texture(ctx
, dims
,
2185 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2188 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2189 srcAddr
, srcPacking
);
2191 else if (!ctx
->_ImageTransferState
&&
2193 srcType
== GL_UNSIGNED_BYTE
&&
2194 can_swizzle(baseInternalFormat
) &&
2195 can_swizzle(srcFormat
)) {
2198 /* dstmap - how to swizzle from RGBA to dst format:
2200 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2201 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2202 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2212 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2213 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2222 dstmap
[2] = ZERO
; /* ? */
2223 dstmap
[3] = ONE
; /* ? */
2225 _mesa_swizzle_ubyte_image(ctx
, dims
,
2230 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2231 dstRowStride
, dstImageOffsets
,
2232 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2237 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2240 srcWidth
, srcHeight
, srcDepth
,
2241 srcFormat
, srcType
, srcAddr
,
2243 const GLchan
*src
= tempImage
;
2244 GLint img
, row
, col
;
2247 for (img
= 0; img
< srcDepth
; img
++) {
2248 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2249 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2250 + dstYoffset
* dstRowStride
2251 + dstXoffset
* texelBytes
;
2252 for (row
= 0; row
< srcHeight
; row
++) {
2253 GLushort
*dstUS
= (GLushort
*) dstRow
;
2254 if (dstFormat
== MESA_FORMAT_AL88
||
2255 dstFormat
== MESA_FORMAT_RG88
) {
2256 for (col
= 0; col
< srcWidth
; col
++) {
2257 /* src[0] is luminance, src[1] is alpha */
2258 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2259 CHAN_TO_UBYTE(src
[0]) );
2264 for (col
= 0; col
< srcWidth
; col
++) {
2265 /* src[0] is luminance, src[1] is alpha */
2266 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2267 CHAN_TO_UBYTE(src
[0]) );
2271 dstRow
+= dstRowStride
;
2274 free((void *) tempImage
);
2281 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2284 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2286 const GLboolean littleEndian
= _mesa_little_endian();
2287 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2288 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2290 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2291 dstFormat
== MESA_FORMAT_AL1616_REV
||
2292 dstFormat
== MESA_FORMAT_RG1616
||
2293 dstFormat
== MESA_FORMAT_RG1616_REV
);
2294 ASSERT(texelBytes
== 4);
2296 if (!ctx
->_ImageTransferState
&&
2297 !srcPacking
->SwapBytes
&&
2298 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2299 baseInternalFormat
== srcFormat
&&
2300 srcType
== GL_UNSIGNED_SHORT
&&
2302 /* simple memcpy path */
2303 memcpy_texture(ctx
, dims
,
2304 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2307 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2308 srcAddr
, srcPacking
);
2312 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2315 srcWidth
, srcHeight
, srcDepth
,
2316 srcFormat
, srcType
, srcAddr
,
2318 ctx
->_ImageTransferState
);
2319 const GLfloat
*src
= tempImage
;
2320 GLint img
, row
, col
;
2323 for (img
= 0; img
< srcDepth
; img
++) {
2324 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2325 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2326 + dstYoffset
* dstRowStride
2327 + dstXoffset
* texelBytes
;
2328 for (row
= 0; row
< srcHeight
; row
++) {
2329 GLuint
*dstUI
= (GLuint
*) dstRow
;
2330 if (dstFormat
== MESA_FORMAT_AL1616
||
2331 dstFormat
== MESA_FORMAT_RG1616
) {
2332 for (col
= 0; col
< srcWidth
; col
++) {
2335 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2336 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2337 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2342 for (col
= 0; col
< srcWidth
; col
++) {
2345 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2346 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2347 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2351 dstRow
+= dstRowStride
;
2354 free((void *) tempImage
);
2360 /* Texstore for R16, A16, L16, I16. */
2362 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2364 const GLboolean littleEndian
= _mesa_little_endian();
2365 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2366 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2368 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2369 dstFormat
== MESA_FORMAT_A16
||
2370 dstFormat
== MESA_FORMAT_L16
||
2371 dstFormat
== MESA_FORMAT_I16
);
2372 ASSERT(texelBytes
== 2);
2374 if (!ctx
->_ImageTransferState
&&
2375 !srcPacking
->SwapBytes
&&
2376 baseInternalFormat
== srcFormat
&&
2377 srcType
== GL_UNSIGNED_SHORT
&&
2379 /* simple memcpy path */
2380 memcpy_texture(ctx
, dims
,
2381 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2384 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2385 srcAddr
, srcPacking
);
2389 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2392 srcWidth
, srcHeight
, srcDepth
,
2393 srcFormat
, srcType
, srcAddr
,
2395 ctx
->_ImageTransferState
);
2396 const GLfloat
*src
= tempImage
;
2397 GLint img
, row
, col
;
2400 for (img
= 0; img
< srcDepth
; img
++) {
2401 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2402 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2403 + dstYoffset
* dstRowStride
2404 + dstXoffset
* texelBytes
;
2405 for (row
= 0; row
< srcHeight
; row
++) {
2406 GLushort
*dstUS
= (GLushort
*) dstRow
;
2407 for (col
= 0; col
< srcWidth
; col
++) {
2410 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2414 dstRow
+= dstRowStride
;
2417 free((void *) tempImage
);
2424 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2426 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2427 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2429 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2430 ASSERT(texelBytes
== 8);
2432 if (!ctx
->_ImageTransferState
&&
2433 !srcPacking
->SwapBytes
&&
2434 baseInternalFormat
== GL_RGBA
&&
2435 srcFormat
== GL_RGBA
&&
2436 srcType
== GL_UNSIGNED_SHORT
) {
2437 /* simple memcpy path */
2438 memcpy_texture(ctx
, dims
,
2439 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2442 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2443 srcAddr
, srcPacking
);
2447 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2450 srcWidth
, srcHeight
, srcDepth
,
2451 srcFormat
, srcType
, srcAddr
,
2453 ctx
->_ImageTransferState
);
2454 const GLfloat
*src
= tempImage
;
2455 GLint img
, row
, col
;
2458 for (img
= 0; img
< srcDepth
; img
++) {
2459 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2460 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2461 + dstYoffset
* dstRowStride
2462 + dstXoffset
* texelBytes
;
2463 for (row
= 0; row
< srcHeight
; row
++) {
2464 GLushort
*dstUS
= (GLushort
*) dstRow
;
2465 for (col
= 0; col
< srcWidth
; col
++) {
2466 GLushort r
, g
, b
, a
;
2468 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2469 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2470 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2471 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2478 dstRow
+= dstRowStride
;
2481 free((void *) tempImage
);
2488 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2490 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2491 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2493 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R_16
||
2494 dstFormat
== MESA_FORMAT_SIGNED_RG_16
||
2495 dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2496 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2498 if (!ctx
->_ImageTransferState
&&
2499 !srcPacking
->SwapBytes
&&
2500 baseInternalFormat
== GL_RGBA
&&
2501 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2502 srcFormat
== GL_RGBA
&&
2503 srcType
== GL_SHORT
) {
2504 /* simple memcpy path */
2505 memcpy_texture(ctx
, dims
,
2506 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2509 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2510 srcAddr
, srcPacking
);
2514 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2517 srcWidth
, srcHeight
, srcDepth
,
2518 srcFormat
, srcType
, srcAddr
,
2520 ctx
->_ImageTransferState
);
2521 const GLfloat
*src
= tempImage
;
2522 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2523 GLint img
, row
, col
;
2528 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2529 * 3 or 4 components/pixel here.
2531 for (img
= 0; img
< srcDepth
; img
++) {
2532 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2533 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2534 + dstYoffset
* dstRowStride
2535 + dstXoffset
* texelBytes
;
2536 for (row
= 0; row
< srcHeight
; row
++) {
2537 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2538 for (col
= 0; col
< srcWidth
; col
++) {
2540 for (c
= 0; c
< comps
; c
++) {
2542 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2543 dstRowS
[col
* comps
+ c
] = p
;
2546 dstRow
+= dstRowStride
;
2547 src
+= 4 * srcWidth
;
2550 free((void *) tempImage
);
2557 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2559 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2560 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2562 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2563 ASSERT(texelBytes
== 1);
2565 if (!ctx
->_ImageTransferState
&&
2566 !srcPacking
->SwapBytes
&&
2567 baseInternalFormat
== GL_RGB
&&
2568 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2569 /* simple memcpy path */
2570 memcpy_texture(ctx
, dims
,
2571 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2574 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2575 srcAddr
, srcPacking
);
2579 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2582 srcWidth
, srcHeight
, srcDepth
,
2583 srcFormat
, srcType
, srcAddr
,
2585 const GLchan
*src
= tempImage
;
2586 GLint img
, row
, col
;
2589 for (img
= 0; img
< srcDepth
; img
++) {
2590 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2591 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2592 + dstYoffset
* dstRowStride
2593 + dstXoffset
* texelBytes
;
2594 for (row
= 0; row
< srcHeight
; row
++) {
2595 for (col
= 0; col
< srcWidth
; col
++) {
2596 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2597 CHAN_TO_UBYTE(src
[GCOMP
]),
2598 CHAN_TO_UBYTE(src
[BCOMP
]) );
2601 dstRow
+= dstRowStride
;
2604 free((void *) tempImage
);
2611 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2614 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2616 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2617 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2619 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2620 dstFormat
== MESA_FORMAT_L8
||
2621 dstFormat
== MESA_FORMAT_I8
||
2622 dstFormat
== MESA_FORMAT_R8
);
2623 ASSERT(texelBytes
== 1);
2625 if (!ctx
->_ImageTransferState
&&
2626 !srcPacking
->SwapBytes
&&
2627 baseInternalFormat
== srcFormat
&&
2628 srcType
== GL_UNSIGNED_BYTE
) {
2629 /* simple memcpy path */
2630 memcpy_texture(ctx
, dims
,
2631 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2634 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2635 srcAddr
, srcPacking
);
2637 else if (!ctx
->_ImageTransferState
&&
2638 srcType
== GL_UNSIGNED_BYTE
&&
2639 can_swizzle(baseInternalFormat
) &&
2640 can_swizzle(srcFormat
)) {
2643 /* dstmap - how to swizzle from RGBA to dst format:
2645 if (dstFormat
== MESA_FORMAT_A8
) {
2651 dstmap
[1] = ZERO
; /* ? */
2652 dstmap
[2] = ZERO
; /* ? */
2653 dstmap
[3] = ONE
; /* ? */
2655 _mesa_swizzle_ubyte_image(ctx
, dims
,
2660 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2661 dstRowStride
, dstImageOffsets
,
2662 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2667 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2670 srcWidth
, srcHeight
, srcDepth
,
2671 srcFormat
, srcType
, srcAddr
,
2673 const GLchan
*src
= tempImage
;
2674 GLint img
, row
, col
;
2677 for (img
= 0; img
< srcDepth
; img
++) {
2678 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2679 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2680 + dstYoffset
* dstRowStride
2681 + dstXoffset
* texelBytes
;
2682 for (row
= 0; row
< srcHeight
; row
++) {
2683 for (col
= 0; col
< srcWidth
; col
++) {
2684 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2686 dstRow
+= dstRowStride
;
2690 free((void *) tempImage
);
2698 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2700 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2702 (void) dims
; (void) baseInternalFormat
;
2703 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2704 ASSERT(texelBytes
== 1);
2705 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2707 if (!ctx
->_ImageTransferState
&&
2708 !srcPacking
->SwapBytes
&&
2709 srcFormat
== GL_COLOR_INDEX
&&
2710 srcType
== GL_UNSIGNED_BYTE
) {
2711 /* simple memcpy path */
2712 memcpy_texture(ctx
, dims
,
2713 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2716 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2717 srcAddr
, srcPacking
);
2722 for (img
= 0; img
< srcDepth
; img
++) {
2723 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2724 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2725 + dstYoffset
* dstRowStride
2726 + dstXoffset
* texelBytes
;
2727 for (row
= 0; row
< srcHeight
; row
++) {
2728 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2729 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2730 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2731 srcType
, src
, srcPacking
,
2732 ctx
->_ImageTransferState
);
2733 dstRow
+= dstRowStride
;
2742 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2745 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2747 const GLboolean littleEndian
= _mesa_little_endian();
2748 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2750 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2752 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2753 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2754 ASSERT(texelBytes
== 2);
2755 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2756 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2757 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2758 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2759 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2761 /* always just memcpy since no pixel transfer ops apply */
2762 memcpy_texture(ctx
, dims
,
2763 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2766 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2767 srcAddr
, srcPacking
);
2769 /* Check if we need byte swapping */
2770 /* XXX the logic here _might_ be wrong */
2771 if (srcPacking
->SwapBytes
^
2772 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2773 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2776 for (img
= 0; img
< srcDepth
; img
++) {
2777 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2778 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2779 + dstYoffset
* dstRowStride
2780 + dstXoffset
* texelBytes
;
2781 for (row
= 0; row
< srcHeight
; row
++) {
2782 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2783 dstRow
+= dstRowStride
;
2791 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2793 const GLboolean littleEndian
= _mesa_little_endian();
2794 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2796 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2797 ASSERT(texelBytes
== 2);
2798 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2799 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2800 (srcFormat
== GL_DUDV_ATI
));
2801 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2803 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2805 /* simple memcpy path */
2806 memcpy_texture(ctx
, dims
,
2807 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2810 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2811 srcAddr
, srcPacking
);
2813 else if (srcType
== GL_BYTE
) {
2816 /* dstmap - how to swizzle from RGBA to dst format:
2826 dstmap
[2] = ZERO
; /* ? */
2827 dstmap
[3] = ONE
; /* ? */
2829 _mesa_swizzle_ubyte_image(ctx
, dims
,
2830 GL_LUMINANCE_ALPHA
, /* hack */
2831 GL_UNSIGNED_BYTE
, /* hack */
2832 GL_LUMINANCE_ALPHA
, /* hack */
2834 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2835 dstRowStride
, dstImageOffsets
,
2836 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2840 /* general path - note this is defined for 2d textures only */
2841 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2842 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2843 srcFormat
, srcType
);
2844 GLbyte
*tempImage
, *dst
, *src
;
2847 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2848 * components
* sizeof(GLbyte
));
2852 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2853 srcWidth
, srcHeight
,
2858 for (row
= 0; row
< srcHeight
; row
++) {
2859 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2860 dst
, srcFormat
, srcType
, src
,
2862 dst
+= srcWidth
* components
;
2867 dst
= (GLbyte
*) dstAddr
2868 + dstYoffset
* dstRowStride
2869 + dstXoffset
* texelBytes
;
2870 for (row
= 0; row
< srcHeight
; row
++) {
2871 memcpy(dst
, src
, srcWidth
* texelBytes
);
2872 dst
+= dstRowStride
;
2873 src
+= srcWidth
* texelBytes
;
2875 free((void *) tempImage
);
2882 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2885 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2887 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2888 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2890 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2891 ASSERT(texelBytes
== 1);
2893 /* XXX look at adding optimized paths */
2896 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2899 srcWidth
, srcHeight
, srcDepth
,
2900 srcFormat
, srcType
, srcAddr
,
2902 ctx
->_ImageTransferState
);
2903 const GLfloat
*srcRow
= tempImage
;
2904 GLint img
, row
, col
;
2907 for (img
= 0; img
< srcDepth
; img
++) {
2908 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2909 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2910 + dstYoffset
* dstRowStride
2911 + dstXoffset
* texelBytes
;
2912 for (row
= 0; row
< srcHeight
; row
++) {
2913 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2914 for (col
= 0; col
< srcWidth
; col
++) {
2915 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2917 dstRow
+= dstRowStride
;
2920 free((void *) tempImage
);
2927 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2930 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2932 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2933 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2935 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2936 ASSERT(texelBytes
== 1);
2938 /* XXX look at adding optimized paths */
2941 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2944 srcWidth
, srcHeight
, srcDepth
,
2945 srcFormat
, srcType
, srcAddr
,
2947 ctx
->_ImageTransferState
);
2948 const GLfloat
*srcRow
= tempImage
;
2949 GLint img
, row
, col
;
2952 for (img
= 0; img
< srcDepth
; img
++) {
2953 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2954 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2955 + dstYoffset
* dstRowStride
2956 + dstXoffset
* texelBytes
;
2957 for (row
= 0; row
< srcHeight
; row
++) {
2958 GLushort
*dstUS
= (GLushort
*) dstRow
;
2959 for (col
= 0; col
< srcWidth
; col
++) {
2960 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2961 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2963 dstRow
+= dstRowStride
;
2966 free((void *) tempImage
);
2973 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2976 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2978 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2979 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2981 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2982 ASSERT(texelBytes
== 4);
2986 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2989 srcWidth
, srcHeight
, srcDepth
,
2990 srcFormat
, srcType
, srcAddr
,
2992 ctx
->_ImageTransferState
);
2993 const GLfloat
*srcRow
= tempImage
;
2994 GLint img
, row
, col
;
2997 for (img
= 0; img
< srcDepth
; img
++) {
2998 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2999 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3000 + dstYoffset
* dstRowStride
3001 + dstXoffset
* texelBytes
;
3002 for (row
= 0; row
< srcHeight
; row
++) {
3003 GLuint
*dstUI
= (GLuint
*) dstRow
;
3004 for (col
= 0; col
< srcWidth
; col
++) {
3005 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3006 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3007 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3011 dstRow
+= dstRowStride
;
3014 free((void *) tempImage
);
3022 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3023 * MESA_FORMAT_SIGNED_RGBA8888_REV
3026 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3028 const GLboolean littleEndian
= _mesa_little_endian();
3029 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3030 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3032 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3033 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3034 ASSERT(texelBytes
== 4);
3036 if (!ctx
->_ImageTransferState
&&
3037 !srcPacking
->SwapBytes
&&
3038 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3039 baseInternalFormat
== GL_RGBA
&&
3040 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3041 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3042 /* simple memcpy path */
3043 memcpy_texture(ctx
, dims
,
3044 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3047 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3048 srcAddr
, srcPacking
);
3050 else if (!ctx
->_ImageTransferState
&&
3051 !srcPacking
->SwapBytes
&&
3052 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3053 baseInternalFormat
== GL_RGBA
&&
3054 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3055 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3056 /* simple memcpy path */
3057 memcpy_texture(ctx
, dims
,
3058 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3061 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3062 srcAddr
, srcPacking
);
3064 else if (!ctx
->_ImageTransferState
&&
3065 (srcType
== GL_BYTE
) &&
3066 can_swizzle(baseInternalFormat
) &&
3067 can_swizzle(srcFormat
)) {
3071 /* dstmap - how to swizzle from RGBA to dst format:
3073 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
3074 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
3087 _mesa_swizzle_ubyte_image(ctx
, dims
,
3092 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3093 dstRowStride
, dstImageOffsets
,
3094 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
3099 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3102 srcWidth
, srcHeight
, srcDepth
,
3103 srcFormat
, srcType
, srcAddr
,
3105 ctx
->_ImageTransferState
);
3106 const GLfloat
*srcRow
= tempImage
;
3107 GLint img
, row
, col
;
3110 for (img
= 0; img
< srcDepth
; img
++) {
3111 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3112 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3113 + dstYoffset
* dstRowStride
3114 + dstXoffset
* texelBytes
;
3115 for (row
= 0; row
< srcHeight
; row
++) {
3116 GLuint
*dstUI
= (GLuint
*) dstRow
;
3117 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3118 for (col
= 0; col
< srcWidth
; col
++) {
3119 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3120 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3121 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3122 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3127 for (col
= 0; col
< srcWidth
; col
++) {
3128 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
3129 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
3130 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
3131 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
3135 dstRow
+= dstRowStride
;
3138 free((void *) tempImage
);
3145 * Store a combined depth/stencil texture image.
3148 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3150 const GLuint depthScale
= 0xffffff;
3151 const GLint srcRowStride
3152 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3156 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3157 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
3158 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3160 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3161 ctx
->Pixel
.DepthBias
== 0.0f
&&
3162 !srcPacking
->SwapBytes
) {
3164 memcpy_texture(ctx
, dims
,
3165 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3168 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3169 srcAddr
, srcPacking
);
3171 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
3172 /* In case we only upload depth we need to preserve the stencil */
3173 for (img
= 0; img
< srcDepth
; img
++) {
3174 GLuint
*dstRow
= (GLuint
*) dstAddr
3175 + dstImageOffsets
[dstZoffset
+ img
]
3176 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3179 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3180 srcWidth
, srcHeight
,
3183 for (row
= 0; row
< srcHeight
; row
++) {
3184 GLuint depth
[MAX_WIDTH
];
3185 GLubyte stencil
[MAX_WIDTH
];
3187 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3189 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3190 keepstencil
= GL_TRUE
;
3192 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3193 keepdepth
= GL_TRUE
;
3196 if (keepdepth
== GL_FALSE
)
3197 /* the 24 depth bits will be in the low position: */
3198 _mesa_unpack_depth_span(ctx
, srcWidth
,
3199 GL_UNSIGNED_INT
, /* dst type */
3200 keepstencil
? depth
: dstRow
, /* dst addr */
3202 srcType
, src
, srcPacking
);
3204 if (keepstencil
== GL_FALSE
)
3205 /* get the 8-bit stencil values */
3206 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3207 GL_UNSIGNED_BYTE
, /* dst type */
3208 stencil
, /* dst addr */
3209 srcType
, src
, srcPacking
,
3210 ctx
->_ImageTransferState
);
3212 for (i
= 0; i
< srcWidth
; i
++) {
3214 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3216 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3219 src
+= srcRowStride
;
3220 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3229 * Store a combined depth/stencil texture image.
3232 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3234 const GLuint depthScale
= 0xffffff;
3235 const GLint srcRowStride
3236 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3240 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3241 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3242 srcFormat
== GL_DEPTH_COMPONENT
||
3243 srcFormat
== GL_STENCIL_INDEX
);
3244 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3245 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3247 for (img
= 0; img
< srcDepth
; img
++) {
3248 GLuint
*dstRow
= (GLuint
*) dstAddr
3249 + dstImageOffsets
[dstZoffset
+ img
]
3250 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3253 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3254 srcWidth
, srcHeight
,
3257 for (row
= 0; row
< srcHeight
; row
++) {
3258 GLuint depth
[MAX_WIDTH
];
3259 GLubyte stencil
[MAX_WIDTH
];
3261 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3263 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3264 keepstencil
= GL_TRUE
;
3266 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3267 keepdepth
= GL_TRUE
;
3270 if (keepdepth
== GL_FALSE
)
3271 /* the 24 depth bits will be in the low position: */
3272 _mesa_unpack_depth_span(ctx
, srcWidth
,
3273 GL_UNSIGNED_INT
, /* dst type */
3274 keepstencil
? depth
: dstRow
, /* dst addr */
3276 srcType
, src
, srcPacking
);
3278 if (keepstencil
== GL_FALSE
)
3279 /* get the 8-bit stencil values */
3280 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3281 GL_UNSIGNED_BYTE
, /* dst type */
3282 stencil
, /* dst addr */
3283 srcType
, src
, srcPacking
,
3284 ctx
->_ImageTransferState
);
3286 /* merge stencil values into depth values */
3287 for (i
= 0; i
< srcWidth
; i
++) {
3289 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3291 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3294 src
+= srcRowStride
;
3295 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3303 * Store simple 8-bit/value stencil texture data.
3306 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3308 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3309 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3311 if (!ctx
->_ImageTransferState
&&
3312 !srcPacking
->SwapBytes
&&
3313 baseInternalFormat
== srcFormat
&&
3314 srcType
== GL_UNSIGNED_BYTE
) {
3315 /* simple memcpy path */
3316 memcpy_texture(ctx
, dims
,
3317 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3320 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3321 srcAddr
, srcPacking
);
3324 const GLint srcRowStride
3325 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3329 for (img
= 0; img
< srcDepth
; img
++) {
3330 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3331 + dstImageOffsets
[dstZoffset
+ img
]
3332 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3335 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3336 srcWidth
, srcHeight
,
3339 for (row
= 0; row
< srcHeight
; row
++) {
3340 GLubyte stencil
[MAX_WIDTH
];
3343 /* get the 8-bit stencil values */
3344 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3345 GL_UNSIGNED_BYTE
, /* dst type */
3346 stencil
, /* dst addr */
3347 srcType
, src
, srcPacking
,
3348 ctx
->_ImageTransferState
);
3349 /* merge stencil values into depth values */
3350 for (i
= 0; i
< srcWidth
; i
++)
3351 dstRow
[i
] = stencil
[i
];
3353 src
+= srcRowStride
;
3354 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3365 * Store an image in any of the formats:
3366 * _mesa_texformat_rgba_float32
3367 * _mesa_texformat_rgb_float32
3368 * _mesa_texformat_alpha_float32
3369 * _mesa_texformat_luminance_float32
3370 * _mesa_texformat_luminance_alpha_float32
3371 * _mesa_texformat_intensity_float32
3374 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3376 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3377 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3378 const GLint components
= _mesa_components_in_format(baseFormat
);
3380 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3381 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3382 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3383 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3384 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3385 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3386 ASSERT(baseInternalFormat
== GL_RGBA
||
3387 baseInternalFormat
== GL_RGB
||
3388 baseInternalFormat
== GL_ALPHA
||
3389 baseInternalFormat
== GL_LUMINANCE
||
3390 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3391 baseInternalFormat
== GL_INTENSITY
);
3392 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3394 if (!ctx
->_ImageTransferState
&&
3395 !srcPacking
->SwapBytes
&&
3396 baseInternalFormat
== srcFormat
&&
3397 srcType
== GL_FLOAT
) {
3398 /* simple memcpy path */
3399 memcpy_texture(ctx
, dims
,
3400 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3403 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3404 srcAddr
, srcPacking
);
3408 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3411 srcWidth
, srcHeight
, srcDepth
,
3412 srcFormat
, srcType
, srcAddr
,
3414 ctx
->_ImageTransferState
);
3415 const GLfloat
*srcRow
= tempImage
;
3420 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3421 for (img
= 0; img
< srcDepth
; img
++) {
3422 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3423 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3424 + dstYoffset
* dstRowStride
3425 + dstXoffset
* texelBytes
;
3426 for (row
= 0; row
< srcHeight
; row
++) {
3427 memcpy(dstRow
, srcRow
, bytesPerRow
);
3428 dstRow
+= dstRowStride
;
3429 srcRow
+= srcWidth
* components
;
3433 free((void *) tempImage
);
3441 * As above, but store 16-bit floats.
3444 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3446 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3447 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3448 const GLint components
= _mesa_components_in_format(baseFormat
);
3450 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3451 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3452 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3453 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3454 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3455 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3456 ASSERT(baseInternalFormat
== GL_RGBA
||
3457 baseInternalFormat
== GL_RGB
||
3458 baseInternalFormat
== GL_ALPHA
||
3459 baseInternalFormat
== GL_LUMINANCE
||
3460 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3461 baseInternalFormat
== GL_INTENSITY
);
3462 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3464 if (!ctx
->_ImageTransferState
&&
3465 !srcPacking
->SwapBytes
&&
3466 baseInternalFormat
== srcFormat
&&
3467 srcType
== GL_HALF_FLOAT_ARB
) {
3468 /* simple memcpy path */
3469 memcpy_texture(ctx
, dims
,
3470 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3473 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3474 srcAddr
, srcPacking
);
3478 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3481 srcWidth
, srcHeight
, srcDepth
,
3482 srcFormat
, srcType
, srcAddr
,
3484 ctx
->_ImageTransferState
);
3485 const GLfloat
*src
= tempImage
;
3489 for (img
= 0; img
< srcDepth
; img
++) {
3490 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3491 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3492 + dstYoffset
* dstRowStride
3493 + dstXoffset
* texelBytes
;
3494 for (row
= 0; row
< srcHeight
; row
++) {
3495 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3497 for (i
= 0; i
< srcWidth
* components
; i
++) {
3498 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3500 dstRow
+= dstRowStride
;
3501 src
+= srcWidth
* components
;
3505 free((void *) tempImage
);
3511 /* non-normalized, signed int8 */
3513 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3515 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3516 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3517 const GLint components
= _mesa_components_in_format(baseFormat
);
3519 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3520 ASSERT(baseInternalFormat
== GL_RGBA
||
3521 baseInternalFormat
== GL_RGB
||
3522 baseInternalFormat
== GL_ALPHA
||
3523 baseInternalFormat
== GL_LUMINANCE
||
3524 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3525 baseInternalFormat
== GL_INTENSITY
);
3526 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3528 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3529 * to integer formats.
3531 if (!srcPacking
->SwapBytes
&&
3532 baseInternalFormat
== srcFormat
&&
3533 srcType
== GL_BYTE
) {
3534 /* simple memcpy path */
3535 memcpy_texture(ctx
, dims
,
3536 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3539 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3540 srcAddr
, srcPacking
);
3544 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3547 srcWidth
, srcHeight
, srcDepth
,
3548 srcFormat
, srcType
, srcAddr
,
3550 const GLfloat
*src
= tempImage
;
3554 for (img
= 0; img
< srcDepth
; img
++) {
3555 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3556 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3557 + dstYoffset
* dstRowStride
3558 + dstXoffset
* texelBytes
;
3559 for (row
= 0; row
< srcHeight
; row
++) {
3560 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3562 for (i
= 0; i
< srcWidth
* components
; i
++) {
3563 dstTexel
[i
] = (GLbyte
) src
[i
];
3565 dstRow
+= dstRowStride
;
3566 src
+= srcWidth
* components
;
3570 free((void *) tempImage
);
3576 /* non-normalized, signed int16 */
3578 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3580 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3581 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3582 const GLint components
= _mesa_components_in_format(baseFormat
);
3584 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3585 ASSERT(baseInternalFormat
== GL_RGBA
||
3586 baseInternalFormat
== GL_RGB
||
3587 baseInternalFormat
== GL_ALPHA
||
3588 baseInternalFormat
== GL_LUMINANCE
||
3589 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3590 baseInternalFormat
== GL_INTENSITY
);
3591 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3593 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3594 * to integer formats.
3596 if (!srcPacking
->SwapBytes
&&
3597 baseInternalFormat
== srcFormat
&&
3598 srcType
== GL_SHORT
) {
3599 /* simple memcpy path */
3600 memcpy_texture(ctx
, dims
,
3601 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3604 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3605 srcAddr
, srcPacking
);
3609 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3612 srcWidth
, srcHeight
, srcDepth
,
3613 srcFormat
, srcType
, srcAddr
,
3615 const GLfloat
*src
= tempImage
;
3619 for (img
= 0; img
< srcDepth
; img
++) {
3620 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3621 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3622 + dstYoffset
* dstRowStride
3623 + dstXoffset
* texelBytes
;
3624 for (row
= 0; row
< srcHeight
; row
++) {
3625 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3627 for (i
= 0; i
< srcWidth
* components
; i
++) {
3628 dstTexel
[i
] = (GLint
) src
[i
];
3630 dstRow
+= dstRowStride
;
3631 src
+= srcWidth
* components
;
3635 free((void *) tempImage
);
3641 /* non-normalized, signed int32 */
3643 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3645 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3646 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3647 const GLint components
= _mesa_components_in_format(baseFormat
);
3649 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3650 ASSERT(baseInternalFormat
== GL_RGBA
||
3651 baseInternalFormat
== GL_RGB
||
3652 baseInternalFormat
== GL_ALPHA
||
3653 baseInternalFormat
== GL_LUMINANCE
||
3654 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3655 baseInternalFormat
== GL_INTENSITY
);
3656 ASSERT(texelBytes
== components
* sizeof(GLint
));
3658 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3659 * to integer formats.
3661 if (!srcPacking
->SwapBytes
&&
3662 baseInternalFormat
== srcFormat
&&
3663 srcType
== GL_INT
) {
3664 /* simple memcpy path */
3665 memcpy_texture(ctx
, dims
,
3666 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3669 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3670 srcAddr
, srcPacking
);
3674 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3677 srcWidth
, srcHeight
, srcDepth
,
3678 srcFormat
, srcType
, srcAddr
,
3680 const GLfloat
*src
= tempImage
;
3684 for (img
= 0; img
< srcDepth
; img
++) {
3685 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3686 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3687 + dstYoffset
* dstRowStride
3688 + dstXoffset
* texelBytes
;
3689 for (row
= 0; row
< srcHeight
; row
++) {
3690 GLint
*dstTexel
= (GLint
*) dstRow
;
3692 for (i
= 0; i
< srcWidth
* components
; i
++) {
3693 dstTexel
[i
] = (GLint
) src
[i
];
3695 dstRow
+= dstRowStride
;
3696 src
+= srcWidth
* components
;
3700 free((void *) tempImage
);
3706 /* non-normalized, unsigned int8 */
3708 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3710 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3711 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3712 const GLint components
= _mesa_components_in_format(baseFormat
);
3714 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3715 ASSERT(baseInternalFormat
== GL_RGBA
||
3716 baseInternalFormat
== GL_RGB
||
3717 baseInternalFormat
== GL_ALPHA
||
3718 baseInternalFormat
== GL_LUMINANCE
||
3719 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3720 baseInternalFormat
== GL_INTENSITY
);
3721 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3723 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3724 * to integer formats.
3726 if (!srcPacking
->SwapBytes
&&
3727 baseInternalFormat
== srcFormat
&&
3728 srcType
== GL_UNSIGNED_BYTE
) {
3729 /* simple memcpy path */
3730 memcpy_texture(ctx
, dims
,
3731 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3734 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3735 srcAddr
, srcPacking
);
3739 const GLuint
*tempImage
=
3740 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3741 srcWidth
, srcHeight
, srcDepth
,
3742 srcFormat
, srcType
, srcAddr
, srcPacking
);
3743 const GLuint
*src
= tempImage
;
3747 for (img
= 0; img
< srcDepth
; img
++) {
3748 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3749 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3750 + dstYoffset
* dstRowStride
3751 + dstXoffset
* texelBytes
;
3752 for (row
= 0; row
< srcHeight
; row
++) {
3753 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3755 for (i
= 0; i
< srcWidth
* components
; i
++) {
3756 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3758 dstRow
+= dstRowStride
;
3759 src
+= srcWidth
* components
;
3763 free((void *) tempImage
);
3769 /* non-normalized, unsigned int16 */
3771 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3773 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3774 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3775 const GLint components
= _mesa_components_in_format(baseFormat
);
3777 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3778 ASSERT(baseInternalFormat
== GL_RGBA
||
3779 baseInternalFormat
== GL_RGB
||
3780 baseInternalFormat
== GL_ALPHA
||
3781 baseInternalFormat
== GL_LUMINANCE
||
3782 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3783 baseInternalFormat
== GL_INTENSITY
);
3784 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3786 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3787 * to integer formats.
3789 if (!srcPacking
->SwapBytes
&&
3790 baseInternalFormat
== srcFormat
&&
3791 srcType
== GL_UNSIGNED_SHORT
) {
3792 /* simple memcpy path */
3793 memcpy_texture(ctx
, dims
,
3794 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3797 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3798 srcAddr
, srcPacking
);
3802 const GLuint
*tempImage
=
3803 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3804 srcWidth
, srcHeight
, srcDepth
,
3805 srcFormat
, srcType
, srcAddr
, srcPacking
);
3806 const GLuint
*src
= tempImage
;
3810 for (img
= 0; img
< srcDepth
; img
++) {
3811 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3812 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3813 + dstYoffset
* dstRowStride
3814 + dstXoffset
* texelBytes
;
3815 for (row
= 0; row
< srcHeight
; row
++) {
3816 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3818 for (i
= 0; i
< srcWidth
* components
; i
++) {
3819 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3821 dstRow
+= dstRowStride
;
3822 src
+= srcWidth
* components
;
3826 free((void *) tempImage
);
3832 /* non-normalized, unsigned int32 */
3834 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3836 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3837 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3838 const GLint components
= _mesa_components_in_format(baseFormat
);
3840 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3841 ASSERT(baseInternalFormat
== GL_RGBA
||
3842 baseInternalFormat
== GL_RGB
||
3843 baseInternalFormat
== GL_ALPHA
||
3844 baseInternalFormat
== GL_LUMINANCE
||
3845 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3846 baseInternalFormat
== GL_INTENSITY
);
3847 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3849 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3850 * to integer formats.
3852 if (!srcPacking
->SwapBytes
&&
3853 baseInternalFormat
== srcFormat
&&
3854 srcType
== GL_UNSIGNED_INT
) {
3855 /* simple memcpy path */
3856 memcpy_texture(ctx
, dims
,
3857 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3860 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3861 srcAddr
, srcPacking
);
3865 const GLuint
*tempImage
=
3866 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3867 srcWidth
, srcHeight
, srcDepth
,
3868 srcFormat
, srcType
, srcAddr
, srcPacking
);
3869 const GLuint
*src
= tempImage
;
3873 for (img
= 0; img
< srcDepth
; img
++) {
3874 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3875 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3876 + dstYoffset
* dstRowStride
3877 + dstXoffset
* texelBytes
;
3878 for (row
= 0; row
< srcHeight
; row
++) {
3879 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3881 for (i
= 0; i
< srcWidth
* components
; i
++) {
3882 dstTexel
[i
] = src
[i
];
3884 dstRow
+= dstRowStride
;
3885 src
+= srcWidth
* components
;
3889 free((void *) tempImage
);
3897 #if FEATURE_EXT_texture_sRGB
3899 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3901 gl_format newDstFormat
;
3904 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3906 /* reuse normal rgb texstore code */
3907 newDstFormat
= MESA_FORMAT_RGB888
;
3909 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3910 newDstFormat
, dstAddr
,
3911 dstXoffset
, dstYoffset
, dstZoffset
,
3912 dstRowStride
, dstImageOffsets
,
3913 srcWidth
, srcHeight
, srcDepth
,
3915 srcAddr
, srcPacking
);
3921 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3923 gl_format newDstFormat
;
3926 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3928 /* reuse normal rgba texstore code */
3929 newDstFormat
= MESA_FORMAT_RGBA8888
;
3930 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3931 newDstFormat
, dstAddr
,
3932 dstXoffset
, dstYoffset
, dstZoffset
,
3933 dstRowStride
, dstImageOffsets
,
3934 srcWidth
, srcHeight
, srcDepth
,
3936 srcAddr
, srcPacking
);
3942 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3944 gl_format newDstFormat
;
3947 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3949 /* reuse normal rgba texstore code */
3950 newDstFormat
= MESA_FORMAT_ARGB8888
;
3952 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3953 newDstFormat
, dstAddr
,
3954 dstXoffset
, dstYoffset
, dstZoffset
,
3955 dstRowStride
, dstImageOffsets
,
3956 srcWidth
, srcHeight
, srcDepth
,
3958 srcAddr
, srcPacking
);
3964 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3966 gl_format newDstFormat
;
3969 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3971 newDstFormat
= MESA_FORMAT_L8
;
3973 /* _mesa_textore_a8 handles luminance8 too */
3974 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3975 newDstFormat
, dstAddr
,
3976 dstXoffset
, dstYoffset
, dstZoffset
,
3977 dstRowStride
, dstImageOffsets
,
3978 srcWidth
, srcHeight
, srcDepth
,
3980 srcAddr
, srcPacking
);
3986 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3988 gl_format newDstFormat
;
3991 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3993 /* reuse normal luminance/alpha texstore code */
3994 newDstFormat
= MESA_FORMAT_AL88
;
3996 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3997 newDstFormat
, dstAddr
,
3998 dstXoffset
, dstYoffset
, dstZoffset
,
3999 dstRowStride
, dstImageOffsets
,
4000 srcWidth
, srcHeight
, srcDepth
,
4002 srcAddr
, srcPacking
);
4008 /* these are used only in texstore_funcs[] below */
4009 #define _mesa_texstore_srgb8 NULL
4010 #define _mesa_texstore_srgba8 NULL
4011 #define _mesa_texstore_sargb8 NULL
4012 #define _mesa_texstore_sl8 NULL
4013 #define _mesa_texstore_sla8 NULL
4015 #endif /* FEATURE_EXT_texture_sRGB */
4021 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4022 * XXX this is somewhat temporary.
4024 static const struct {
4026 StoreTexImageFunc Store
;
4028 texstore_funcs
[MESA_FORMAT_COUNT
] =
4030 { MESA_FORMAT_NONE
, NULL
},
4031 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
4032 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
4033 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
4034 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
4035 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
4036 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
4037 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
4038 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
4039 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
4040 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
4041 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
4042 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
4043 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
4044 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
4045 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
4046 { MESA_FORMAT_AL44
, _mesa_texstore_unorm44
},
4047 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
4048 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
4049 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
4050 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
4051 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
4052 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
4053 { MESA_FORMAT_A16
, _mesa_texstore_unorm16
},
4054 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
4055 { MESA_FORMAT_L16
, _mesa_texstore_unorm16
},
4056 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
4057 { MESA_FORMAT_I16
, _mesa_texstore_unorm16
},
4058 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
4059 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
4060 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
4061 { MESA_FORMAT_R8
, _mesa_texstore_a8
},
4062 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
4063 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
4064 { MESA_FORMAT_R16
, _mesa_texstore_unorm16
},
4065 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
4066 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
4067 { MESA_FORMAT_ARGB2101010
, _mesa_texstore_argb2101010
},
4068 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
4069 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
4070 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
4071 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
4072 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
4073 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
4074 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
4075 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
4076 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
4077 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
4078 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
4079 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
4080 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4081 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4082 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4083 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4084 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
4085 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
4086 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
4087 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
4088 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
4089 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
4090 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
4091 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
4092 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
4093 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
4094 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4095 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4096 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
4097 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
4098 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
4099 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
4100 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
4101 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
4103 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
4104 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
4105 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
4106 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
4107 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
4108 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
4110 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
4112 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
4113 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
4114 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
4116 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
4117 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
4119 { MESA_FORMAT_SIGNED_R_16
, _mesa_texstore_signed_rgba_16
},
4120 { MESA_FORMAT_SIGNED_RG_16
, _mesa_texstore_signed_rgba_16
},
4121 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
4122 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
4123 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
}
4128 _mesa_texstore_null(TEXSTORE_PARAMS
)
4130 (void) ctx
; (void) dims
;
4131 (void) baseInternalFormat
;
4134 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4135 (void) dstRowStride
; (void) dstImageOffsets
;
4136 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4137 (void) srcFormat
; (void) srcType
;
4141 /* should never happen */
4142 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4148 * Return the StoreTexImageFunc pointer to store an image in the given format.
4150 static StoreTexImageFunc
4151 _mesa_get_texstore_func(gl_format format
)
4155 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
4156 ASSERT(texstore_funcs
[i
].Name
== i
);
4159 ASSERT(texstore_funcs
[format
].Name
== format
);
4161 if (texstore_funcs
[format
].Store
)
4162 return texstore_funcs
[format
].Store
;
4164 return _mesa_texstore_null
;
4169 * Store user data into texture memory.
4170 * Called via glTex[Sub]Image1/2/3D()
4173 _mesa_texstore(TEXSTORE_PARAMS
)
4175 StoreTexImageFunc storeImage
;
4178 storeImage
= _mesa_get_texstore_func(dstFormat
);
4180 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4181 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
4182 dstRowStride
, dstImageOffsets
,
4183 srcWidth
, srcHeight
, srcDepth
,
4184 srcFormat
, srcType
, srcAddr
, srcPacking
);
4190 * Check if an unpack PBO is active prior to fetching a texture image.
4191 * If so, do bounds checking and map the buffer into main memory.
4192 * Any errors detected will be recorded.
4193 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4196 _mesa_validate_pbo_teximage(struct gl_context
*ctx
, GLuint dimensions
,
4197 GLsizei width
, GLsizei height
, GLsizei depth
,
4198 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4199 const struct gl_pixelstore_attrib
*unpack
,
4200 const char *funcName
)
4204 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
4208 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
4209 format
, type
, pixels
)) {
4210 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4214 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4215 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
4217 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped)");
4221 return ADD_POINTERS(buf
, pixels
);
4226 * Check if an unpack PBO is active prior to fetching a compressed texture
4228 * If so, do bounds checking and map the buffer into main memory.
4229 * Any errors detected will be recorded.
4230 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4233 _mesa_validate_pbo_compressed_teximage(struct gl_context
*ctx
,
4234 GLsizei imageSize
, const GLvoid
*pixels
,
4235 const struct gl_pixelstore_attrib
*packing
,
4236 const char *funcName
)
4240 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
4241 /* not using a PBO - return pointer unchanged */
4244 if ((const GLubyte
*) pixels
+ imageSize
>
4245 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
4246 /* out of bounds read! */
4247 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access)");
4251 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4252 GL_READ_ONLY_ARB
, packing
->BufferObj
);
4254 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
4258 return ADD_POINTERS(buf
, pixels
);
4263 * This function must be called after either of the validate_pbo_*_teximage()
4264 * functions. It unmaps the PBO buffer if it was mapped earlier.
4267 _mesa_unmap_teximage_pbo(struct gl_context
*ctx
,
4268 const struct gl_pixelstore_attrib
*unpack
)
4270 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
4271 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4277 /** Return texture size in bytes */
4279 texture_size(const struct gl_texture_image
*texImage
)
4281 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4282 texImage
->Height
, texImage
->Depth
);
4287 /** Return row stride in bytes */
4289 texture_row_stride(const struct gl_texture_image
*texImage
)
4291 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4299 * This is the software fallback for Driver.TexImage1D()
4300 * and Driver.CopyTexImage1D().
4301 * \sa _mesa_store_teximage2d()
4304 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4305 GLint internalFormat
,
4306 GLint width
, GLint border
,
4307 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4308 const struct gl_pixelstore_attrib
*packing
,
4309 struct gl_texture_object
*texObj
,
4310 struct gl_texture_image
*texImage
)
4315 /* allocate memory */
4316 sizeInBytes
= texture_size(texImage
);
4317 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4318 if (!texImage
->Data
) {
4319 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4323 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4324 pixels
, packing
, "glTexImage1D");
4326 /* Note: we check for a NULL image pointer here, _after_ we allocated
4327 * memory for the texture. That's what the GL spec calls for.
4332 const GLint dstRowStride
= 0;
4333 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4334 texImage
->TexFormat
,
4336 0, 0, 0, /* dstX/Y/Zoffset */
4338 texImage
->ImageOffsets
,
4340 format
, type
, pixels
, packing
);
4342 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4346 _mesa_unmap_teximage_pbo(ctx
, packing
);
4351 * This is the software fallback for Driver.TexImage2D()
4352 * and Driver.CopyTexImage2D().
4354 * This function is oriented toward storing images in main memory, rather
4355 * than VRAM. Device driver's can easily plug in their own replacement.
4358 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4359 GLint internalFormat
,
4360 GLint width
, GLint height
, GLint border
,
4361 GLenum format
, GLenum type
, const void *pixels
,
4362 const struct gl_pixelstore_attrib
*packing
,
4363 struct gl_texture_object
*texObj
,
4364 struct gl_texture_image
*texImage
)
4369 /* allocate memory */
4370 sizeInBytes
= texture_size(texImage
);
4371 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4372 if (!texImage
->Data
) {
4373 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4377 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4378 pixels
, packing
, "glTexImage2D");
4380 /* Note: we check for a NULL image pointer here, _after_ we allocated
4381 * memory for the texture. That's what the GL spec calls for.
4386 GLint dstRowStride
= texture_row_stride(texImage
);
4387 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4388 texImage
->TexFormat
,
4390 0, 0, 0, /* dstX/Y/Zoffset */
4392 texImage
->ImageOffsets
,
4394 format
, type
, pixels
, packing
);
4396 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4400 _mesa_unmap_teximage_pbo(ctx
, packing
);
4406 * This is the software fallback for Driver.TexImage3D()
4407 * and Driver.CopyTexImage3D().
4408 * \sa _mesa_store_teximage2d()
4411 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4412 GLint internalFormat
,
4413 GLint width
, GLint height
, GLint depth
, GLint border
,
4414 GLenum format
, GLenum type
, const void *pixels
,
4415 const struct gl_pixelstore_attrib
*packing
,
4416 struct gl_texture_object
*texObj
,
4417 struct gl_texture_image
*texImage
)
4422 /* allocate memory */
4423 sizeInBytes
= texture_size(texImage
);
4424 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4425 if (!texImage
->Data
) {
4426 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4430 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4431 type
, pixels
, packing
, "glTexImage3D");
4433 /* Note: we check for a NULL image pointer here, _after_ we allocated
4434 * memory for the texture. That's what the GL spec calls for.
4439 GLint dstRowStride
= texture_row_stride(texImage
);
4440 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4441 texImage
->TexFormat
,
4443 0, 0, 0, /* dstX/Y/Zoffset */
4445 texImage
->ImageOffsets
,
4446 width
, height
, depth
,
4447 format
, type
, pixels
, packing
);
4449 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4453 _mesa_unmap_teximage_pbo(ctx
, packing
);
4460 * This is the software fallback for Driver.TexSubImage1D()
4461 * and Driver.CopyTexSubImage1D().
4464 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4465 GLint xoffset
, GLint width
,
4466 GLenum format
, GLenum type
, const void *pixels
,
4467 const struct gl_pixelstore_attrib
*packing
,
4468 struct gl_texture_object
*texObj
,
4469 struct gl_texture_image
*texImage
)
4471 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4472 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4473 pixels
, packing
, "glTexSubImage1D");
4478 const GLint dstRowStride
= 0;
4479 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4480 texImage
->TexFormat
,
4482 xoffset
, 0, 0, /* offsets */
4484 texImage
->ImageOffsets
,
4486 format
, type
, pixels
, packing
);
4488 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4492 _mesa_unmap_teximage_pbo(ctx
, packing
);
4498 * This is the software fallback for Driver.TexSubImage2D()
4499 * and Driver.CopyTexSubImage2D().
4502 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4503 GLint xoffset
, GLint yoffset
,
4504 GLint width
, GLint height
,
4505 GLenum format
, GLenum type
, const void *pixels
,
4506 const struct gl_pixelstore_attrib
*packing
,
4507 struct gl_texture_object
*texObj
,
4508 struct gl_texture_image
*texImage
)
4510 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4511 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4512 pixels
, packing
, "glTexSubImage2D");
4517 GLint dstRowStride
= texture_row_stride(texImage
);
4518 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4519 texImage
->TexFormat
,
4521 xoffset
, yoffset
, 0,
4523 texImage
->ImageOffsets
,
4525 format
, type
, pixels
, packing
);
4527 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4531 _mesa_unmap_teximage_pbo(ctx
, packing
);
4536 * This is the software fallback for Driver.TexSubImage3D().
4537 * and Driver.CopyTexSubImage3D().
4540 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4541 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4542 GLint width
, GLint height
, GLint depth
,
4543 GLenum format
, GLenum type
, const void *pixels
,
4544 const struct gl_pixelstore_attrib
*packing
,
4545 struct gl_texture_object
*texObj
,
4546 struct gl_texture_image
*texImage
)
4548 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4549 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4550 type
, pixels
, packing
,
4556 GLint dstRowStride
= texture_row_stride(texImage
);
4557 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4558 texImage
->TexFormat
,
4560 xoffset
, yoffset
, zoffset
,
4562 texImage
->ImageOffsets
,
4563 width
, height
, depth
,
4564 format
, type
, pixels
, packing
);
4566 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4570 _mesa_unmap_teximage_pbo(ctx
, packing
);
4575 * Fallback for Driver.CompressedTexImage1D()
4578 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4579 GLenum target
, GLint level
,
4580 GLint internalFormat
,
4581 GLint width
, GLint border
,
4582 GLsizei imageSize
, const GLvoid
*data
,
4583 struct gl_texture_object
*texObj
,
4584 struct gl_texture_image
*texImage
)
4586 /* this space intentionally left blank */
4588 (void) target
; (void) level
;
4589 (void) internalFormat
;
4590 (void) width
; (void) border
;
4591 (void) imageSize
; (void) data
;
4599 * Fallback for Driver.CompressedTexImage2D()
4602 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4603 GLenum target
, GLint level
,
4604 GLint internalFormat
,
4605 GLint width
, GLint height
, GLint border
,
4606 GLsizei imageSize
, const GLvoid
*data
,
4607 struct gl_texture_object
*texObj
,
4608 struct gl_texture_image
*texImage
)
4610 (void) width
; (void) height
; (void) border
;
4612 /* This is pretty simple, basically just do a memcpy without worrying
4613 * about the usual image unpacking or image transfer operations.
4617 ASSERT(texImage
->Width
> 0);
4618 ASSERT(texImage
->Height
> 0);
4619 ASSERT(texImage
->Depth
== 1);
4620 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4622 /* allocate storage */
4623 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4624 if (!texImage
->Data
) {
4625 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4629 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4631 "glCompressedTexImage2D");
4636 memcpy(texImage
->Data
, data
, imageSize
);
4638 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4644 * Fallback for Driver.CompressedTexImage3D()
4647 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4648 GLenum target
, GLint level
,
4649 GLint internalFormat
,
4650 GLint width
, GLint height
, GLint depth
,
4652 GLsizei imageSize
, const GLvoid
*data
,
4653 struct gl_texture_object
*texObj
,
4654 struct gl_texture_image
*texImage
)
4656 /* this space intentionally left blank */
4658 (void) target
; (void) level
;
4659 (void) internalFormat
;
4660 (void) width
; (void) height
; (void) depth
;
4662 (void) imageSize
; (void) data
;
4670 * Fallback for Driver.CompressedTexSubImage1D()
4673 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4675 GLint xoffset
, GLsizei width
,
4677 GLsizei imageSize
, const GLvoid
*data
,
4678 struct gl_texture_object
*texObj
,
4679 struct gl_texture_image
*texImage
)
4681 /* there are no compressed 1D texture formats yet */
4683 (void) target
; (void) level
;
4684 (void) xoffset
; (void) width
;
4686 (void) imageSize
; (void) data
;
4693 * Fallback for Driver.CompressedTexSubImage2D()
4696 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4698 GLint xoffset
, GLint yoffset
,
4699 GLsizei width
, GLsizei height
,
4701 GLsizei imageSize
, const GLvoid
*data
,
4702 struct gl_texture_object
*texObj
,
4703 struct gl_texture_image
*texImage
)
4705 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4709 const gl_format texFormat
= texImage
->TexFormat
;
4710 const GLint destWidth
= texImage
->Width
;
4713 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4718 /* these should have been caught sooner */
4719 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4720 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4721 ASSERT((xoffset
% bw
) == 0);
4722 ASSERT((yoffset
% bh
) == 0);
4724 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4725 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4727 "glCompressedTexSubImage2D");
4731 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4732 src
= (const GLubyte
*) data
;
4734 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4735 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4736 texFormat
, destWidth
,
4737 (GLubyte
*) texImage
->Data
);
4739 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4740 rows
= height
/ bh
; /* rows in blocks */
4742 /* copy rows of blocks */
4743 for (i
= 0; i
< rows
; i
++) {
4744 memcpy(dest
, src
, bytesPerRow
);
4745 dest
+= destRowStride
;
4746 src
+= srcRowStride
;
4749 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4754 * Fallback for Driver.CompressedTexSubImage3D()
4757 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4759 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4760 GLsizei width
, GLsizei height
, GLsizei depth
,
4762 GLsizei imageSize
, const GLvoid
*data
,
4763 struct gl_texture_object
*texObj
,
4764 struct gl_texture_image
*texImage
)
4766 /* there are no compressed 3D texture formats yet */
4768 (void) target
; (void) level
;
4769 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4770 (void) width
; (void) height
; (void) depth
;
4772 (void) imageSize
; (void) data
;