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"
60 #include "mfeatures.h"
77 * Texture image storage function.
79 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
83 * Return GL_TRUE if the given image format is one that be converted
84 * to another format by swizzling.
87 can_swizzle(GLenum logicalBaseFormat
)
89 switch (logicalBaseFormat
) {
92 case GL_LUMINANCE_ALPHA
:
128 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
129 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
130 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
131 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
134 static const struct {
137 GLubyte from_rgba
[6];
138 } mappings
[MAX_IDX
] =
148 MAP4(ZERO
, ZERO
, ZERO
, 0),
178 MAP4(0, ZERO
, ZERO
, ONE
),
184 MAP4(ZERO
, 0, ZERO
, ONE
),
190 MAP4(ZERO
, ZERO
, 0, ONE
),
214 MAP4(0, 1, ZERO
, ONE
),
222 * Convert a GL image format enum to an IDX_* value (see above).
225 get_map_idx(GLenum value
)
228 case GL_LUMINANCE
: return IDX_LUMINANCE
;
229 case GL_ALPHA
: return IDX_ALPHA
;
230 case GL_INTENSITY
: return IDX_INTENSITY
;
231 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
232 case GL_RGB
: return IDX_RGB
;
233 case GL_RGBA
: return IDX_RGBA
;
234 case GL_RED
: return IDX_RED
;
235 case GL_GREEN
: return IDX_GREEN
;
236 case GL_BLUE
: return IDX_BLUE
;
237 case GL_BGR
: return IDX_BGR
;
238 case GL_BGRA
: return IDX_BGRA
;
239 case GL_ABGR_EXT
: return IDX_ABGR
;
240 case GL_RG
: return IDX_RG
;
242 _mesa_problem(NULL
, "Unexpected inFormat");
249 * When promoting texture formats (see below) we need to compute the
250 * mapping of dest components back to source components.
251 * This function does that.
252 * \param inFormat the incoming format of the texture
253 * \param outFormat the final texture format
254 * \return map[6] a full 6-component map
257 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
260 const int inFmt
= get_map_idx(inFormat
);
261 const int outFmt
= get_map_idx(outFormat
);
262 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
263 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
266 for (i
= 0; i
< 4; i
++)
267 map
[i
] = in2rgba
[rgba2out
[i
]];
273 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
274 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
275 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
287 * Make a temporary (color) texture image with GLfloat components.
288 * Apply all needed pixel unpacking and pixel transfer operations.
289 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
290 * Suppose the user specifies GL_LUMINANCE as the internal texture format
291 * but the graphics hardware doesn't support luminance textures. So, we might
292 * use an RGB hardware format instead.
293 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
295 * \param ctx the rendering context
296 * \param dims image dimensions: 1, 2 or 3
297 * \param logicalBaseFormat basic texture derived from the user's
298 * internal texture format value
299 * \param textureBaseFormat the actual basic format of the texture
300 * \param srcWidth source image width
301 * \param srcHeight source image height
302 * \param srcDepth source image depth
303 * \param srcFormat source image format
304 * \param srcType source image type
305 * \param srcAddr source image address
306 * \param srcPacking source image pixel packing
307 * \return resulting image with format = textureBaseFormat and type = GLfloat.
310 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
311 GLenum logicalBaseFormat
,
312 GLenum textureBaseFormat
,
313 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
314 GLenum srcFormat
, GLenum srcType
,
315 const GLvoid
*srcAddr
,
316 const struct gl_pixelstore_attrib
*srcPacking
,
317 GLbitfield transferOps
)
320 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
321 const GLint srcStride
=
322 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
326 ASSERT(dims
>= 1 && dims
<= 3);
328 ASSERT(logicalBaseFormat
== GL_RGBA
||
329 logicalBaseFormat
== GL_RGB
||
330 logicalBaseFormat
== GL_RG
||
331 logicalBaseFormat
== GL_RED
||
332 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
333 logicalBaseFormat
== GL_LUMINANCE
||
334 logicalBaseFormat
== GL_ALPHA
||
335 logicalBaseFormat
== GL_INTENSITY
||
336 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
338 ASSERT(textureBaseFormat
== GL_RGBA
||
339 textureBaseFormat
== GL_RGB
||
340 textureBaseFormat
== GL_RG
||
341 textureBaseFormat
== GL_RED
||
342 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
343 textureBaseFormat
== GL_LUMINANCE
||
344 textureBaseFormat
== GL_ALPHA
||
345 textureBaseFormat
== GL_INTENSITY
||
346 textureBaseFormat
== GL_DEPTH_COMPONENT
);
348 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
349 * components
* sizeof(GLfloat
));
354 for (img
= 0; img
< srcDepth
; img
++) {
356 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
360 for (row
= 0; row
< srcHeight
; row
++) {
361 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
362 dst
, srcFormat
, srcType
, src
,
363 srcPacking
, transferOps
);
364 dst
+= srcWidth
* components
;
369 if (logicalBaseFormat
!= textureBaseFormat
) {
371 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
372 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
377 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
378 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
379 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
381 /* The actual texture format should have at least as many components
382 * as the logical texture format.
384 ASSERT(texComponents
>= logComponents
);
386 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
387 * texComponents
* sizeof(GLfloat
));
393 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
395 n
= srcWidth
* srcHeight
* srcDepth
;
396 for (i
= 0; i
< n
; i
++) {
398 for (k
= 0; k
< texComponents
; k
++) {
401 newImage
[i
* texComponents
+ k
] = 0.0F
;
403 newImage
[i
* texComponents
+ k
] = 1.0F
;
405 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
410 tempImage
= newImage
;
418 * Make temporary image with uint pixel values. Used for unsigned
419 * integer-valued textures.
422 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
423 GLenum logicalBaseFormat
,
424 GLenum textureBaseFormat
,
425 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
426 GLenum srcFormat
, GLenum srcType
,
427 const GLvoid
*srcAddr
,
428 const struct gl_pixelstore_attrib
*srcPacking
)
431 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
432 const GLint srcStride
=
433 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
437 ASSERT(dims
>= 1 && dims
<= 3);
439 ASSERT(logicalBaseFormat
== GL_RGBA
||
440 logicalBaseFormat
== GL_RGB
||
441 logicalBaseFormat
== GL_RG
||
442 logicalBaseFormat
== GL_RED
||
443 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
444 logicalBaseFormat
== GL_LUMINANCE
||
445 logicalBaseFormat
== GL_INTENSITY
||
446 logicalBaseFormat
== GL_ALPHA
);
448 ASSERT(textureBaseFormat
== GL_RGBA
||
449 textureBaseFormat
== GL_RGB
||
450 textureBaseFormat
== GL_RG
||
451 textureBaseFormat
== GL_RED
||
452 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
453 textureBaseFormat
== GL_LUMINANCE
||
454 textureBaseFormat
== GL_INTENSITY
||
455 textureBaseFormat
== GL_ALPHA
);
457 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
458 * components
* sizeof(GLuint
));
463 for (img
= 0; img
< srcDepth
; img
++) {
465 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
469 for (row
= 0; row
< srcHeight
; row
++) {
470 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
471 dst
, srcFormat
, srcType
, src
,
473 dst
+= srcWidth
* components
;
478 if (logicalBaseFormat
!= textureBaseFormat
) {
480 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
481 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
486 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
487 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
488 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
490 /* The actual texture format should have at least as many components
491 * as the logical texture format.
493 ASSERT(texComponents
>= logComponents
);
495 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
496 * texComponents
* sizeof(GLuint
));
502 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
504 n
= srcWidth
* srcHeight
* srcDepth
;
505 for (i
= 0; i
< n
; i
++) {
507 for (k
= 0; k
< texComponents
; k
++) {
510 newImage
[i
* texComponents
+ k
] = 0;
512 newImage
[i
* texComponents
+ k
] = 1;
514 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
519 tempImage
= newImage
;
528 * Make a temporary (color) texture image with GLubyte components.
529 * Apply all needed pixel unpacking and pixel transfer operations.
530 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
531 * Suppose the user specifies GL_LUMINANCE as the internal texture format
532 * but the graphics hardware doesn't support luminance textures. So, we might
533 * use an RGB hardware format instead.
534 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
536 * \param ctx the rendering context
537 * \param dims image dimensions: 1, 2 or 3
538 * \param logicalBaseFormat basic texture derived from the user's
539 * internal texture format value
540 * \param textureBaseFormat the actual basic format of the texture
541 * \param srcWidth source image width
542 * \param srcHeight source image height
543 * \param srcDepth source image depth
544 * \param srcFormat source image format
545 * \param srcType source image type
546 * \param srcAddr source image address
547 * \param srcPacking source image pixel packing
548 * \return resulting image with format = textureBaseFormat and type = GLubyte.
551 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
552 GLenum logicalBaseFormat
,
553 GLenum textureBaseFormat
,
554 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
555 GLenum srcFormat
, GLenum srcType
,
556 const GLvoid
*srcAddr
,
557 const struct gl_pixelstore_attrib
*srcPacking
)
559 GLuint transferOps
= ctx
->_ImageTransferState
;
560 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
562 GLubyte
*tempImage
, *dst
;
564 ASSERT(dims
>= 1 && dims
<= 3);
566 ASSERT(logicalBaseFormat
== GL_RGBA
||
567 logicalBaseFormat
== GL_RGB
||
568 logicalBaseFormat
== GL_RG
||
569 logicalBaseFormat
== GL_RED
||
570 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
571 logicalBaseFormat
== GL_LUMINANCE
||
572 logicalBaseFormat
== GL_ALPHA
||
573 logicalBaseFormat
== GL_INTENSITY
);
575 ASSERT(textureBaseFormat
== GL_RGBA
||
576 textureBaseFormat
== GL_RGB
||
577 textureBaseFormat
== GL_RG
||
578 textureBaseFormat
== GL_RED
||
579 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
580 textureBaseFormat
== GL_LUMINANCE
||
581 textureBaseFormat
== GL_ALPHA
||
582 textureBaseFormat
== GL_INTENSITY
);
584 /* unpack and transfer the source image */
585 tempImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
586 * components
* sizeof(GLubyte
));
592 for (img
= 0; img
< srcDepth
; img
++) {
593 const GLint srcStride
=
594 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
596 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
600 for (row
= 0; row
< srcHeight
; row
++) {
601 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
602 srcFormat
, srcType
, src
, srcPacking
,
604 dst
+= srcWidth
* components
;
609 if (logicalBaseFormat
!= textureBaseFormat
) {
610 /* one more conversion step */
611 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
612 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
617 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
618 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
619 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
621 /* The actual texture format should have at least as many components
622 * as the logical texture format.
624 ASSERT(texComponents
>= logComponents
);
626 newImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
627 * texComponents
* sizeof(GLubyte
));
633 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
635 n
= srcWidth
* srcHeight
* srcDepth
;
636 for (i
= 0; i
< n
; i
++) {
638 for (k
= 0; k
< texComponents
; k
++) {
641 newImage
[i
* texComponents
+ k
] = 0;
643 newImage
[i
* texComponents
+ k
] = 255;
645 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
650 tempImage
= newImage
;
658 * Copy GLubyte pixels from <src> to <dst> with swizzling.
659 * \param dst destination pixels
660 * \param dstComponents number of color components in destination pixels
661 * \param src source pixels
662 * \param srcComponents number of color components in source pixels
663 * \param map the swizzle mapping. map[X] says where to find the X component
664 * in the source image's pixels. For example, if the source image
665 * is GL_BGRA and X = red, map[0] yields 2.
666 * \param count number of pixels to copy/swizzle.
669 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
670 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
672 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
675 for (i = 0; i < count; i++) { \
677 if (srcComps == 4) { \
678 COPY_4UBV(tmp, src); \
681 for (j = 0; j < srcComps; j++) { \
686 for (j = 0; j < dstComps; j++) { \
687 dst[j] = tmp[map[j]]; \
698 ASSERT(srcComponents
<= 4);
699 ASSERT(dstComponents
<= 4);
701 switch (dstComponents
) {
703 switch (srcComponents
) {
705 SWZ_CPY(dst
, src
, count
, 4, 4);
708 SWZ_CPY(dst
, src
, count
, 4, 3);
711 SWZ_CPY(dst
, src
, count
, 4, 2);
714 SWZ_CPY(dst
, src
, count
, 4, 1);
721 switch (srcComponents
) {
723 SWZ_CPY(dst
, src
, count
, 3, 4);
726 SWZ_CPY(dst
, src
, count
, 3, 3);
729 SWZ_CPY(dst
, src
, count
, 3, 2);
732 SWZ_CPY(dst
, src
, count
, 3, 1);
739 switch (srcComponents
) {
741 SWZ_CPY(dst
, src
, count
, 2, 4);
744 SWZ_CPY(dst
, src
, count
, 2, 3);
747 SWZ_CPY(dst
, src
, count
, 2, 2);
750 SWZ_CPY(dst
, src
, count
, 2, 1);
757 switch (srcComponents
) {
759 SWZ_CPY(dst
, src
, count
, 1, 4);
762 SWZ_CPY(dst
, src
, count
, 1, 3);
765 SWZ_CPY(dst
, src
, count
, 1, 2);
768 SWZ_CPY(dst
, src
, count
, 1, 1);
782 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
783 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
787 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
788 * mapping array depending on endianness.
790 static const GLubyte
*
791 type_mapping( GLenum srcType
)
795 case GL_UNSIGNED_BYTE
:
797 case GL_UNSIGNED_INT_8_8_8_8
:
798 return _mesa_little_endian() ? map_3210
: map_identity
;
799 case GL_UNSIGNED_INT_8_8_8_8_REV
:
800 return _mesa_little_endian() ? map_identity
: map_3210
;
808 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
809 * mapping array depending on pixelstore byte swapping state.
811 static const GLubyte
*
812 byteswap_mapping( GLboolean swapBytes
,
820 case GL_UNSIGNED_BYTE
:
822 case GL_UNSIGNED_INT_8_8_8_8
:
823 case GL_UNSIGNED_INT_8_8_8_8_REV
:
833 * Transfer a GLubyte texture image with component swizzling.
836 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
841 GLenum baseInternalFormat
,
843 const GLubyte
*rgba2dst
,
844 GLuint dstComponents
,
849 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
850 const GLvoid
*srcAddr
,
851 const struct gl_pixelstore_attrib
*srcPacking
)
853 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
854 const GLubyte
*srctype2ubyte
, *swap
;
855 GLubyte map
[4], src2base
[6], base2rgba
[6];
857 const GLint srcRowStride
=
858 _mesa_image_row_stride(srcPacking
, srcWidth
,
859 srcFormat
, GL_UNSIGNED_BYTE
);
860 const GLint srcImageStride
861 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
863 const GLubyte
*srcImage
864 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
865 srcWidth
, srcHeight
, srcFormat
,
866 GL_UNSIGNED_BYTE
, 0, 0, 0);
870 /* Translate from src->baseInternal->GL_RGBA->dst. This will
871 * correctly deal with RGBA->RGB->RGBA conversions where the final
872 * A value must be 0xff regardless of the incoming alpha values.
874 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
875 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
876 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
877 srctype2ubyte
= type_mapping(srcType
);
880 for (i
= 0; i
< 4; i
++)
881 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
883 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
885 if (srcComponents
== dstComponents
&&
886 srcRowStride
== dstRowStride
&&
887 srcRowStride
== srcWidth
* srcComponents
&&
889 /* 1 and 2D images only */
890 GLubyte
*dstImage
= dstSlices
[0];
891 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
892 srcWidth
* srcHeight
);
896 for (img
= 0; img
< srcDepth
; img
++) {
897 const GLubyte
*srcRow
= srcImage
;
898 GLubyte
*dstRow
= dstSlices
[img
];
899 for (row
= 0; row
< srcHeight
; row
++) {
900 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
901 dstRow
+= dstRowStride
;
902 srcRow
+= srcRowStride
;
904 srcImage
+= srcImageStride
;
911 * Teximage storage routine for when a simple memcpy will do.
912 * No pixel transfer operations or special texel encodings allowed.
913 * 1D, 2D and 3D images supported.
916 memcpy_texture(struct gl_context
*ctx
,
921 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
922 GLenum srcFormat
, GLenum srcType
,
923 const GLvoid
*srcAddr
,
924 const struct gl_pixelstore_attrib
*srcPacking
)
926 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
928 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
929 srcWidth
, srcHeight
, srcFormat
, srcType
);
930 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
931 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
932 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
933 const GLint bytesPerRow
= srcWidth
* texelBytes
;
935 if (dstRowStride
== srcRowStride
&&
936 dstRowStride
== bytesPerRow
) {
937 /* memcpy image by image */
939 for (img
= 0; img
< srcDepth
; img
++) {
940 GLubyte
*dstImage
= dstSlices
[img
];
941 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
942 srcImage
+= srcImageStride
;
946 /* memcpy row by row */
948 for (img
= 0; img
< srcDepth
; img
++) {
949 const GLubyte
*srcRow
= srcImage
;
950 GLubyte
*dstRow
= dstSlices
[img
];
951 for (row
= 0; row
< srcHeight
; row
++) {
952 memcpy(dstRow
, srcRow
, bytesPerRow
);
953 dstRow
+= dstRowStride
;
954 srcRow
+= srcRowStride
;
956 srcImage
+= srcImageStride
;
964 * Store a 32-bit integer or float depth component texture image.
967 _mesa_texstore_z32(TEXSTORE_PARAMS
)
969 const GLuint depthScale
= 0xffffffff;
972 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
973 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
974 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
976 if (dstFormat
== MESA_FORMAT_Z32
)
977 dstType
= GL_UNSIGNED_INT
;
981 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
982 ctx
->Pixel
.DepthBias
== 0.0f
&&
983 !srcPacking
->SwapBytes
&&
984 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
985 srcFormat
== GL_DEPTH_COMPONENT
&&
986 srcType
== dstType
) {
987 /* simple memcpy path */
988 memcpy_texture(ctx
, dims
,
990 dstRowStride
, dstSlices
,
991 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
992 srcAddr
, srcPacking
);
997 for (img
= 0; img
< srcDepth
; img
++) {
998 GLubyte
*dstRow
= dstSlices
[img
];
999 for (row
= 0; row
< srcHeight
; row
++) {
1000 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1001 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1002 _mesa_unpack_depth_span(ctx
, srcWidth
,
1004 depthScale
, srcType
, src
, srcPacking
);
1005 dstRow
+= dstRowStride
;
1014 * Store a 24-bit integer depth component texture image.
1017 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1019 const GLuint depthScale
= 0xffffff;
1022 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1027 for (img
= 0; img
< srcDepth
; img
++) {
1028 GLubyte
*dstRow
= dstSlices
[img
];
1029 for (row
= 0; row
< srcHeight
; row
++) {
1030 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1031 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1032 _mesa_unpack_depth_span(ctx
, srcWidth
,
1033 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1034 depthScale
, srcType
, src
, srcPacking
);
1035 dstRow
+= dstRowStride
;
1044 * Store a 24-bit integer depth component texture image.
1047 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1049 const GLuint depthScale
= 0xffffff;
1052 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1057 for (img
= 0; img
< srcDepth
; img
++) {
1058 GLubyte
*dstRow
= dstSlices
[img
];
1059 for (row
= 0; row
< srcHeight
; row
++) {
1060 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1061 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1062 GLuint
*dst
= (GLuint
*) dstRow
;
1064 _mesa_unpack_depth_span(ctx
, srcWidth
,
1065 GL_UNSIGNED_INT
, dst
,
1066 depthScale
, srcType
, src
, srcPacking
);
1067 for (i
= 0; i
< srcWidth
; i
++)
1069 dstRow
+= dstRowStride
;
1078 * Store a 16-bit integer depth component texture image.
1081 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1083 const GLuint depthScale
= 0xffff;
1085 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1086 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1088 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1089 ctx
->Pixel
.DepthBias
== 0.0f
&&
1090 !srcPacking
->SwapBytes
&&
1091 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1092 srcFormat
== GL_DEPTH_COMPONENT
&&
1093 srcType
== GL_UNSIGNED_SHORT
) {
1094 /* simple memcpy path */
1095 memcpy_texture(ctx
, dims
,
1097 dstRowStride
, dstSlices
,
1098 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1099 srcAddr
, srcPacking
);
1104 for (img
= 0; img
< srcDepth
; img
++) {
1105 GLubyte
*dstRow
= dstSlices
[img
];
1106 for (row
= 0; row
< srcHeight
; row
++) {
1107 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1108 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1109 GLushort
*dst16
= (GLushort
*) dstRow
;
1110 _mesa_unpack_depth_span(ctx
, srcWidth
,
1111 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1112 srcType
, src
, srcPacking
);
1113 dstRow
+= dstRowStride
;
1122 * Store an rgb565 or rgb565_rev texture image.
1125 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1127 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1129 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1130 dstFormat
== MESA_FORMAT_RGB565_REV
);
1131 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1133 if (!ctx
->_ImageTransferState
&&
1134 !srcPacking
->SwapBytes
&&
1135 dstFormat
== MESA_FORMAT_RGB565
&&
1136 baseInternalFormat
== GL_RGB
&&
1137 srcFormat
== GL_RGB
&&
1138 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1139 /* simple memcpy path */
1140 memcpy_texture(ctx
, dims
,
1142 dstRowStride
, dstSlices
,
1143 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1144 srcAddr
, srcPacking
);
1146 else if (!ctx
->_ImageTransferState
&&
1147 !srcPacking
->SwapBytes
&&
1148 baseInternalFormat
== GL_RGB
&&
1149 srcFormat
== GL_RGB
&&
1150 srcType
== GL_UNSIGNED_BYTE
&&
1152 /* do optimized tex store */
1153 const GLint srcRowStride
=
1154 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1155 const GLubyte
*src
= (const GLubyte
*)
1156 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1157 srcFormat
, srcType
, 0, 0, 0);
1158 GLubyte
*dst
= dstSlices
[0];
1160 for (row
= 0; row
< srcHeight
; row
++) {
1161 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1162 GLushort
*dstUS
= (GLushort
*) dst
;
1163 /* check for byteswapped format */
1164 if (dstFormat
== MESA_FORMAT_RGB565
) {
1165 for (col
= 0; col
< srcWidth
; col
++) {
1166 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1171 for (col
= 0; col
< srcWidth
; col
++) {
1172 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1176 dst
+= dstRowStride
;
1177 src
+= srcRowStride
;
1182 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1185 srcWidth
, srcHeight
, srcDepth
,
1186 srcFormat
, srcType
, srcAddr
,
1188 const GLubyte
*src
= tempImage
;
1189 GLint img
, row
, col
;
1192 for (img
= 0; img
< srcDepth
; img
++) {
1193 GLubyte
*dstRow
= dstSlices
[img
];
1194 for (row
= 0; row
< srcHeight
; row
++) {
1195 GLushort
*dstUS
= (GLushort
*) dstRow
;
1196 /* check for byteswapped format */
1197 if (dstFormat
== MESA_FORMAT_RGB565
) {
1198 for (col
= 0; col
< srcWidth
; col
++) {
1199 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1206 for (col
= 0; col
< srcWidth
; col
++) {
1207 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1213 dstRow
+= dstRowStride
;
1216 free((void *) tempImage
);
1223 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1226 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1228 const GLboolean littleEndian
= _mesa_little_endian();
1229 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1231 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1232 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1233 dstFormat
== MESA_FORMAT_RGBX8888
||
1234 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1235 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1237 if (!ctx
->_ImageTransferState
&&
1238 !srcPacking
->SwapBytes
&&
1239 (dstFormat
== MESA_FORMAT_RGBA8888
||
1240 dstFormat
== MESA_FORMAT_RGBX8888
) &&
1241 baseInternalFormat
== GL_RGBA
&&
1242 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1243 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1244 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1245 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1246 /* simple memcpy path */
1247 memcpy_texture(ctx
, dims
,
1249 dstRowStride
, dstSlices
,
1250 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1251 srcAddr
, srcPacking
);
1253 else if (!ctx
->_ImageTransferState
&&
1254 !srcPacking
->SwapBytes
&&
1255 (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1256 dstFormat
== MESA_FORMAT_RGBX8888_REV
) &&
1257 baseInternalFormat
== GL_RGBA
&&
1258 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1259 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1260 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1261 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1262 /* simple memcpy path */
1263 memcpy_texture(ctx
, dims
,
1265 dstRowStride
, dstSlices
,
1266 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1267 srcAddr
, srcPacking
);
1269 else if (!ctx
->_ImageTransferState
&&
1270 (srcType
== GL_UNSIGNED_BYTE
||
1271 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1272 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1273 can_swizzle(baseInternalFormat
) &&
1274 can_swizzle(srcFormat
)) {
1278 /* dstmap - how to swizzle from RGBA to dst format:
1280 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1281 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1282 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1283 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1296 _mesa_swizzle_ubyte_image(ctx
, dims
,
1301 dstRowStride
, dstSlices
,
1302 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1307 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1310 srcWidth
, srcHeight
, srcDepth
,
1311 srcFormat
, srcType
, srcAddr
,
1313 const GLubyte
*src
= tempImage
;
1314 GLint img
, row
, col
;
1317 for (img
= 0; img
< srcDepth
; img
++) {
1318 GLubyte
*dstRow
= dstSlices
[img
];
1319 for (row
= 0; row
< srcHeight
; row
++) {
1320 GLuint
*dstUI
= (GLuint
*) dstRow
;
1321 if (dstFormat
== MESA_FORMAT_RGBA8888
||
1322 dstFormat
== MESA_FORMAT_RGBX8888
) {
1323 for (col
= 0; col
< srcWidth
; col
++) {
1324 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1332 for (col
= 0; col
< srcWidth
; col
++) {
1333 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1340 dstRow
+= dstRowStride
;
1343 free((void *) tempImage
);
1350 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1352 const GLboolean littleEndian
= _mesa_little_endian();
1353 const GLenum baseFormat
= GL_RGBA
;
1355 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1356 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1357 dstFormat
== MESA_FORMAT_XRGB8888
||
1358 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1359 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1361 if (!ctx
->_ImageTransferState
&&
1362 !srcPacking
->SwapBytes
&&
1363 (dstFormat
== MESA_FORMAT_ARGB8888
||
1364 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1365 baseInternalFormat
== GL_RGBA
&&
1366 srcFormat
== GL_BGRA
&&
1367 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1368 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1369 /* simple memcpy path (little endian) */
1370 memcpy_texture(ctx
, dims
,
1372 dstRowStride
, dstSlices
,
1373 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1374 srcAddr
, srcPacking
);
1376 else if (!ctx
->_ImageTransferState
&&
1377 !srcPacking
->SwapBytes
&&
1378 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1379 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1380 baseInternalFormat
== GL_RGBA
&&
1381 srcFormat
== GL_BGRA
&&
1382 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1383 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1384 /* simple memcpy path (big endian) */
1385 memcpy_texture(ctx
, dims
,
1387 dstRowStride
, dstSlices
,
1388 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1389 srcAddr
, srcPacking
);
1391 else if (!ctx
->_ImageTransferState
&&
1392 !srcPacking
->SwapBytes
&&
1393 (dstFormat
== MESA_FORMAT_ARGB8888
||
1394 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1395 srcFormat
== GL_RGB
&&
1396 (baseInternalFormat
== GL_RGBA
||
1397 baseInternalFormat
== GL_RGB
) &&
1398 srcType
== GL_UNSIGNED_BYTE
) {
1400 for (img
= 0; img
< srcDepth
; img
++) {
1401 const GLint srcRowStride
=
1402 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1403 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1404 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1405 GLubyte
*dstRow
= dstSlices
[img
];
1406 for (row
= 0; row
< srcHeight
; row
++) {
1407 GLuint
*d4
= (GLuint
*) dstRow
;
1408 for (col
= 0; col
< srcWidth
; col
++) {
1409 d4
[col
] = PACK_COLOR_8888(0xff,
1410 srcRow
[col
* 3 + RCOMP
],
1411 srcRow
[col
* 3 + GCOMP
],
1412 srcRow
[col
* 3 + BCOMP
]);
1414 dstRow
+= dstRowStride
;
1415 srcRow
+= srcRowStride
;
1419 else if (!ctx
->_ImageTransferState
&&
1420 !srcPacking
->SwapBytes
&&
1421 dstFormat
== MESA_FORMAT_ARGB8888
&&
1422 srcFormat
== GL_RGBA
&&
1423 baseInternalFormat
== GL_RGBA
&&
1424 srcType
== GL_UNSIGNED_BYTE
) {
1425 /* same as above case, but src data has alpha too */
1426 GLint img
, row
, col
;
1427 /* For some reason, streaming copies to write-combined regions
1428 * are extremely sensitive to the characteristics of how the
1429 * source data is retrieved. By reordering the source reads to
1430 * be in-order, the speed of this operation increases by half.
1431 * Strangely the same isn't required for the RGB path, above.
1433 for (img
= 0; img
< srcDepth
; img
++) {
1434 const GLint srcRowStride
=
1435 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1436 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1437 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1438 GLubyte
*dstRow
= dstSlices
[img
];
1439 for (row
= 0; row
< srcHeight
; row
++) {
1440 GLuint
*d4
= (GLuint
*) dstRow
;
1441 for (col
= 0; col
< srcWidth
; col
++) {
1442 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1443 srcRow
[col
* 4 + RCOMP
],
1444 srcRow
[col
* 4 + GCOMP
],
1445 srcRow
[col
* 4 + BCOMP
]);
1447 dstRow
+= dstRowStride
;
1448 srcRow
+= srcRowStride
;
1452 else if (!ctx
->_ImageTransferState
&&
1453 (srcType
== GL_UNSIGNED_BYTE
||
1454 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1455 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1456 can_swizzle(baseInternalFormat
) &&
1457 can_swizzle(srcFormat
)) {
1461 /* dstmap - how to swizzle from RGBA to dst format:
1463 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1464 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1465 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1466 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1467 dstmap
[3] = 3; /* alpha */
1468 dstmap
[2] = 0; /* red */
1469 dstmap
[1] = 1; /* green */
1470 dstmap
[0] = 2; /* blue */
1473 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1474 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1475 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1476 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1483 _mesa_swizzle_ubyte_image(ctx
, dims
,
1490 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1495 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1498 srcWidth
, srcHeight
, srcDepth
,
1499 srcFormat
, srcType
, srcAddr
,
1501 const GLubyte
*src
= tempImage
;
1502 GLint img
, row
, col
;
1505 for (img
= 0; img
< srcDepth
; img
++) {
1506 GLubyte
*dstRow
= dstSlices
[img
];
1507 for (row
= 0; row
< srcHeight
; row
++) {
1508 GLuint
*dstUI
= (GLuint
*) dstRow
;
1509 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1510 for (col
= 0; col
< srcWidth
; col
++) {
1511 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1518 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1519 for (col
= 0; col
< srcWidth
; col
++) {
1520 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1528 for (col
= 0; col
< srcWidth
; col
++) {
1529 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1536 dstRow
+= dstRowStride
;
1539 free((void *) tempImage
);
1546 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1548 const GLboolean littleEndian
= _mesa_little_endian();
1549 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1551 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1552 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1554 if (!ctx
->_ImageTransferState
&&
1555 !srcPacking
->SwapBytes
&&
1556 baseInternalFormat
== GL_RGB
&&
1557 srcFormat
== GL_BGR
&&
1558 srcType
== GL_UNSIGNED_BYTE
&&
1560 /* simple memcpy path */
1561 memcpy_texture(ctx
, dims
,
1563 dstRowStride
, dstSlices
,
1564 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1565 srcAddr
, srcPacking
);
1567 else if (!ctx
->_ImageTransferState
&&
1568 !srcPacking
->SwapBytes
&&
1569 srcFormat
== GL_RGBA
&&
1570 srcType
== GL_UNSIGNED_BYTE
) {
1571 /* extract RGB from RGBA */
1572 GLint img
, row
, col
;
1573 for (img
= 0; img
< srcDepth
; img
++) {
1574 const GLint srcRowStride
=
1575 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1576 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1577 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1578 GLubyte
*dstRow
= dstSlices
[img
];
1579 for (row
= 0; row
< srcHeight
; row
++) {
1580 for (col
= 0; col
< srcWidth
; col
++) {
1581 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1582 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1583 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1585 dstRow
+= dstRowStride
;
1586 srcRow
+= srcRowStride
;
1590 else if (!ctx
->_ImageTransferState
&&
1591 srcType
== GL_UNSIGNED_BYTE
&&
1592 can_swizzle(baseInternalFormat
) &&
1593 can_swizzle(srcFormat
)) {
1597 /* dstmap - how to swizzle from RGBA to dst format:
1602 dstmap
[3] = ONE
; /* ? */
1604 _mesa_swizzle_ubyte_image(ctx
, dims
,
1609 dstRowStride
, dstSlices
,
1610 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1615 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1618 srcWidth
, srcHeight
, srcDepth
,
1619 srcFormat
, srcType
, srcAddr
,
1621 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1622 GLint img
, row
, col
;
1625 for (img
= 0; img
< srcDepth
; img
++) {
1626 GLubyte
*dstRow
= dstSlices
[img
];
1627 for (row
= 0; row
< srcHeight
; row
++) {
1630 for (col
= 0; col
< srcWidth
; col
++) {
1631 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1632 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1633 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1638 for (col
= 0; col
< srcWidth
; col
++) {
1639 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1640 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1641 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1646 for (col
= 0; col
< srcWidth
; col
++) {
1647 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1648 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1649 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1653 dstRow
+= dstRowStride
;
1656 free((void *) tempImage
);
1663 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1665 const GLboolean littleEndian
= _mesa_little_endian();
1666 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1668 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1669 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1671 if (!ctx
->_ImageTransferState
&&
1672 !srcPacking
->SwapBytes
&&
1673 baseInternalFormat
== GL_RGB
&&
1674 srcFormat
== GL_RGB
&&
1675 srcType
== GL_UNSIGNED_BYTE
&&
1677 /* simple memcpy path */
1678 memcpy_texture(ctx
, dims
,
1680 dstRowStride
, dstSlices
,
1681 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1682 srcAddr
, srcPacking
);
1684 else if (!ctx
->_ImageTransferState
&&
1685 !srcPacking
->SwapBytes
&&
1686 srcFormat
== GL_RGBA
&&
1687 srcType
== GL_UNSIGNED_BYTE
) {
1688 /* extract BGR from RGBA */
1690 for (img
= 0; img
< srcDepth
; img
++) {
1691 const GLint srcRowStride
=
1692 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1693 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1694 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1695 GLubyte
*dstRow
= dstSlices
[img
];
1696 for (row
= 0; row
< srcHeight
; row
++) {
1697 for (col
= 0; col
< srcWidth
; col
++) {
1698 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1699 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1700 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1702 dstRow
+= dstRowStride
;
1703 srcRow
+= srcRowStride
;
1707 else if (!ctx
->_ImageTransferState
&&
1708 srcType
== GL_UNSIGNED_BYTE
&&
1709 can_swizzle(baseInternalFormat
) &&
1710 can_swizzle(srcFormat
)) {
1714 /* dstmap - how to swizzle from RGBA to dst format:
1719 dstmap
[3] = ONE
; /* ? */
1721 _mesa_swizzle_ubyte_image(ctx
, dims
,
1726 dstRowStride
, dstSlices
,
1727 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1732 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1735 srcWidth
, srcHeight
, srcDepth
,
1736 srcFormat
, srcType
, srcAddr
,
1738 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1739 GLint img
, row
, col
;
1742 for (img
= 0; img
< srcDepth
; img
++) {
1743 GLubyte
*dstRow
= dstSlices
[img
];
1744 for (row
= 0; row
< srcHeight
; row
++) {
1745 for (col
= 0; col
< srcWidth
; col
++) {
1746 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1747 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1748 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1751 dstRow
+= dstRowStride
;
1754 free((void *) tempImage
);
1761 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1763 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1765 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1766 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1767 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1769 if (!ctx
->_ImageTransferState
&&
1770 !srcPacking
->SwapBytes
&&
1771 dstFormat
== MESA_FORMAT_ARGB4444
&&
1772 baseInternalFormat
== GL_RGBA
&&
1773 srcFormat
== GL_BGRA
&&
1774 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1775 /* simple memcpy path */
1776 memcpy_texture(ctx
, dims
,
1778 dstRowStride
, dstSlices
,
1779 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1780 srcAddr
, srcPacking
);
1784 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1787 srcWidth
, srcHeight
, srcDepth
,
1788 srcFormat
, srcType
, srcAddr
,
1790 const GLubyte
*src
= tempImage
;
1791 GLint img
, row
, col
;
1794 for (img
= 0; img
< srcDepth
; img
++) {
1795 GLubyte
*dstRow
= dstSlices
[img
];
1796 for (row
= 0; row
< srcHeight
; row
++) {
1797 GLushort
*dstUS
= (GLushort
*) dstRow
;
1798 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1799 for (col
= 0; col
< srcWidth
; col
++) {
1800 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1808 for (col
= 0; col
< srcWidth
; col
++) {
1809 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1816 dstRow
+= dstRowStride
;
1819 free((void *) tempImage
);
1825 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1827 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1829 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1830 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1832 if (!ctx
->_ImageTransferState
&&
1833 !srcPacking
->SwapBytes
&&
1834 dstFormat
== MESA_FORMAT_RGBA5551
&&
1835 baseInternalFormat
== GL_RGBA
&&
1836 srcFormat
== GL_RGBA
&&
1837 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1838 /* simple memcpy path */
1839 memcpy_texture(ctx
, dims
,
1841 dstRowStride
, dstSlices
,
1842 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1843 srcAddr
, srcPacking
);
1847 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1850 srcWidth
, srcHeight
, srcDepth
,
1851 srcFormat
, srcType
, srcAddr
,
1853 const GLubyte
*src
=tempImage
;
1854 GLint img
, row
, col
;
1857 for (img
= 0; img
< srcDepth
; img
++) {
1858 GLubyte
*dstRow
= dstSlices
[img
];
1859 for (row
= 0; row
< srcHeight
; row
++) {
1860 GLushort
*dstUS
= (GLushort
*) dstRow
;
1861 for (col
= 0; col
< srcWidth
; col
++) {
1862 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1868 dstRow
+= dstRowStride
;
1871 free((void *) tempImage
);
1877 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1879 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1881 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1882 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1883 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1885 if (!ctx
->_ImageTransferState
&&
1886 !srcPacking
->SwapBytes
&&
1887 dstFormat
== MESA_FORMAT_ARGB1555
&&
1888 baseInternalFormat
== GL_RGBA
&&
1889 srcFormat
== GL_BGRA
&&
1890 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1891 /* simple memcpy path */
1892 memcpy_texture(ctx
, dims
,
1894 dstRowStride
, dstSlices
,
1895 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1896 srcAddr
, srcPacking
);
1900 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1903 srcWidth
, srcHeight
, srcDepth
,
1904 srcFormat
, srcType
, srcAddr
,
1906 const GLubyte
*src
=tempImage
;
1907 GLint img
, row
, col
;
1910 for (img
= 0; img
< srcDepth
; img
++) {
1911 GLubyte
*dstRow
= dstSlices
[img
];
1912 for (row
= 0; row
< srcHeight
; row
++) {
1913 GLushort
*dstUS
= (GLushort
*) dstRow
;
1914 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1915 for (col
= 0; col
< srcWidth
; col
++) {
1916 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
1924 for (col
= 0; col
< srcWidth
; col
++) {
1925 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
1932 dstRow
+= dstRowStride
;
1935 free((void *) tempImage
);
1941 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1944 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1946 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1948 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
1949 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1953 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1956 srcWidth
, srcHeight
, srcDepth
,
1957 srcFormat
, srcType
, srcAddr
,
1959 const GLubyte
*src
= tempImage
;
1960 GLint img
, row
, col
;
1963 for (img
= 0; img
< srcDepth
; img
++) {
1964 GLubyte
*dstRow
= dstSlices
[img
];
1965 for (row
= 0; row
< srcHeight
; row
++) {
1966 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1967 for (col
= 0; col
< srcWidth
; col
++) {
1968 /* src[0] is luminance, src[1] is alpha */
1969 dstUS
[col
] = PACK_COLOR_44( src
[1],
1973 dstRow
+= dstRowStride
;
1976 free((void *) tempImage
);
1983 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1986 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1988 const GLboolean littleEndian
= _mesa_little_endian();
1989 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1991 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1992 dstFormat
== MESA_FORMAT_AL88_REV
);
1993 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1995 if (!ctx
->_ImageTransferState
&&
1996 !srcPacking
->SwapBytes
&&
1997 (dstFormat
== MESA_FORMAT_AL88
&&
1998 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
1999 srcFormat
== GL_LUMINANCE_ALPHA
) &&
2000 srcType
== GL_UNSIGNED_BYTE
&&
2002 /* simple memcpy path */
2003 memcpy_texture(ctx
, dims
,
2005 dstRowStride
, dstSlices
,
2006 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2007 srcAddr
, srcPacking
);
2009 else if (!ctx
->_ImageTransferState
&&
2011 srcType
== GL_UNSIGNED_BYTE
&&
2012 can_swizzle(baseInternalFormat
) &&
2013 can_swizzle(srcFormat
)) {
2016 /* dstmap - how to swizzle from RGBA to dst format:
2018 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2019 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2020 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2029 dstmap
[2] = ZERO
; /* ? */
2030 dstmap
[3] = ONE
; /* ? */
2032 _mesa_swizzle_ubyte_image(ctx
, dims
,
2037 dstRowStride
, dstSlices
,
2038 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2043 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2046 srcWidth
, srcHeight
, srcDepth
,
2047 srcFormat
, srcType
, srcAddr
,
2049 const GLubyte
*src
= tempImage
;
2050 GLint img
, row
, col
;
2053 for (img
= 0; img
< srcDepth
; img
++) {
2054 GLubyte
*dstRow
= dstSlices
[img
];
2055 for (row
= 0; row
< srcHeight
; row
++) {
2056 GLushort
*dstUS
= (GLushort
*) dstRow
;
2057 if (dstFormat
== MESA_FORMAT_AL88
) {
2058 for (col
= 0; col
< srcWidth
; col
++) {
2059 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2060 dstUS
[col
] = PACK_COLOR_88( src
[1],
2066 for (col
= 0; col
< srcWidth
; col
++) {
2067 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2068 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2073 dstRow
+= dstRowStride
;
2076 free((void *) tempImage
);
2083 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2086 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2088 const GLboolean littleEndian
= _mesa_little_endian();
2089 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2091 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2092 dstFormat
== MESA_FORMAT_AL1616_REV
||
2093 dstFormat
== MESA_FORMAT_RG1616
||
2094 dstFormat
== MESA_FORMAT_RG1616_REV
);
2095 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2097 if (!ctx
->_ImageTransferState
&&
2098 !srcPacking
->SwapBytes
&&
2099 (dstFormat
== MESA_FORMAT_AL1616
&&
2100 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2101 srcFormat
== GL_LUMINANCE_ALPHA
) &&
2102 srcType
== GL_UNSIGNED_SHORT
&&
2104 /* simple memcpy path */
2105 memcpy_texture(ctx
, dims
,
2107 dstRowStride
, dstSlices
,
2108 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2109 srcAddr
, srcPacking
);
2113 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2116 srcWidth
, srcHeight
, srcDepth
,
2117 srcFormat
, srcType
, srcAddr
,
2119 ctx
->_ImageTransferState
);
2120 const GLfloat
*src
= tempImage
;
2121 GLint img
, row
, col
;
2124 for (img
= 0; img
< srcDepth
; img
++) {
2125 GLubyte
*dstRow
= dstSlices
[img
];
2126 for (row
= 0; row
< srcHeight
; row
++) {
2127 GLuint
*dstUI
= (GLuint
*) dstRow
;
2128 if (dstFormat
== MESA_FORMAT_AL1616
) {
2129 for (col
= 0; col
< srcWidth
; col
++) {
2132 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2133 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2134 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2139 for (col
= 0; col
< srcWidth
; col
++) {
2142 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2143 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2144 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2148 dstRow
+= dstRowStride
;
2151 free((void *) tempImage
);
2157 /* Texstore for R16, A16, L16, I16. */
2159 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2161 const GLboolean littleEndian
= _mesa_little_endian();
2162 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2164 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2165 dstFormat
== MESA_FORMAT_A16
||
2166 dstFormat
== MESA_FORMAT_L16
||
2167 dstFormat
== MESA_FORMAT_I16
);
2168 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2170 if (!ctx
->_ImageTransferState
&&
2171 !srcPacking
->SwapBytes
&&
2172 baseInternalFormat
== srcFormat
&&
2173 srcType
== GL_UNSIGNED_SHORT
&&
2175 /* simple memcpy path */
2176 memcpy_texture(ctx
, dims
,
2178 dstRowStride
, dstSlices
,
2179 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2180 srcAddr
, srcPacking
);
2184 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2187 srcWidth
, srcHeight
, srcDepth
,
2188 srcFormat
, srcType
, srcAddr
,
2190 ctx
->_ImageTransferState
);
2191 const GLfloat
*src
= tempImage
;
2192 GLint img
, row
, col
;
2195 for (img
= 0; img
< srcDepth
; img
++) {
2196 GLubyte
*dstRow
= dstSlices
[img
];
2197 for (row
= 0; row
< srcHeight
; row
++) {
2198 GLushort
*dstUS
= (GLushort
*) dstRow
;
2199 for (col
= 0; col
< srcWidth
; col
++) {
2202 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2206 dstRow
+= dstRowStride
;
2209 free((void *) tempImage
);
2216 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2218 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2220 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2221 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
2223 if (!ctx
->_ImageTransferState
&&
2224 !srcPacking
->SwapBytes
&&
2225 baseInternalFormat
== GL_RGBA
&&
2226 srcFormat
== GL_RGBA
&&
2227 srcType
== GL_UNSIGNED_SHORT
) {
2228 /* simple memcpy path */
2229 memcpy_texture(ctx
, dims
,
2231 dstRowStride
, dstSlices
,
2232 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2233 srcAddr
, srcPacking
);
2237 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2240 srcWidth
, srcHeight
, srcDepth
,
2241 srcFormat
, srcType
, srcAddr
,
2243 ctx
->_ImageTransferState
);
2244 const GLfloat
*src
= tempImage
;
2245 GLint img
, row
, col
;
2248 for (img
= 0; img
< srcDepth
; img
++) {
2249 GLubyte
*dstRow
= dstSlices
[img
];
2250 for (row
= 0; row
< srcHeight
; row
++) {
2251 GLushort
*dstUS
= (GLushort
*) dstRow
;
2252 for (col
= 0; col
< srcWidth
; col
++) {
2253 GLushort r
, g
, b
, a
;
2255 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2256 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2257 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2258 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2265 dstRow
+= dstRowStride
;
2268 free((void *) tempImage
);
2275 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2277 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2279 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2280 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2282 if (!ctx
->_ImageTransferState
&&
2283 !srcPacking
->SwapBytes
&&
2284 baseInternalFormat
== GL_RGBA
&&
2285 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2286 srcFormat
== GL_RGBA
&&
2287 srcType
== GL_SHORT
) {
2288 /* simple memcpy path */
2289 memcpy_texture(ctx
, dims
,
2291 dstRowStride
, dstSlices
,
2292 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2293 srcAddr
, srcPacking
);
2297 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2300 srcWidth
, srcHeight
, srcDepth
,
2301 srcFormat
, srcType
, srcAddr
,
2303 ctx
->_ImageTransferState
);
2304 const GLfloat
*src
= tempImage
;
2305 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2306 GLint img
, row
, col
;
2311 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2312 * 3 or 4 components/pixel here.
2314 for (img
= 0; img
< srcDepth
; img
++) {
2315 GLubyte
*dstRow
= dstSlices
[img
];
2316 for (row
= 0; row
< srcHeight
; row
++) {
2317 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2318 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2319 for (col
= 0; col
< srcWidth
; col
++) {
2321 for (c
= 0; c
< comps
; c
++) {
2323 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2324 dstRowS
[col
* comps
+ c
] = p
;
2327 dstRow
+= dstRowStride
;
2328 src
+= 4 * srcWidth
;
2330 for (col
= 0; col
< srcWidth
; col
++) {
2332 for (c
= 0; c
< comps
; c
++) {
2334 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2335 dstRowS
[col
* comps
+ c
] = p
;
2338 dstRow
+= dstRowStride
;
2339 src
+= 3 * srcWidth
;
2343 free((void *) tempImage
);
2350 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2352 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2354 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2355 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2357 if (!ctx
->_ImageTransferState
&&
2358 !srcPacking
->SwapBytes
&&
2359 baseInternalFormat
== GL_RGB
&&
2360 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2361 /* simple memcpy path */
2362 memcpy_texture(ctx
, dims
,
2364 dstRowStride
, dstSlices
,
2365 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2366 srcAddr
, srcPacking
);
2370 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2373 srcWidth
, srcHeight
, srcDepth
,
2374 srcFormat
, srcType
, srcAddr
,
2376 const GLubyte
*src
= tempImage
;
2377 GLint img
, row
, col
;
2380 for (img
= 0; img
< srcDepth
; img
++) {
2381 GLubyte
*dstRow
= dstSlices
[img
];
2382 for (row
= 0; row
< srcHeight
; row
++) {
2383 for (col
= 0; col
< srcWidth
; col
++) {
2384 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2389 dstRow
+= dstRowStride
;
2392 free((void *) tempImage
);
2399 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2402 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2404 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2406 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2407 dstFormat
== MESA_FORMAT_L8
||
2408 dstFormat
== MESA_FORMAT_I8
||
2409 dstFormat
== MESA_FORMAT_R8
);
2410 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2412 if (!ctx
->_ImageTransferState
&&
2413 !srcPacking
->SwapBytes
&&
2414 baseInternalFormat
== srcFormat
&&
2415 srcType
== GL_UNSIGNED_BYTE
) {
2416 /* simple memcpy path */
2417 memcpy_texture(ctx
, dims
,
2419 dstRowStride
, dstSlices
,
2420 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2421 srcAddr
, srcPacking
);
2423 else if (!ctx
->_ImageTransferState
&&
2424 srcType
== GL_UNSIGNED_BYTE
&&
2425 can_swizzle(baseInternalFormat
) &&
2426 can_swizzle(srcFormat
)) {
2429 /* dstmap - how to swizzle from RGBA to dst format:
2431 if (dstFormat
== MESA_FORMAT_A8
) {
2437 dstmap
[1] = ZERO
; /* ? */
2438 dstmap
[2] = ZERO
; /* ? */
2439 dstmap
[3] = ONE
; /* ? */
2441 _mesa_swizzle_ubyte_image(ctx
, dims
,
2446 dstRowStride
, dstSlices
,
2447 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2452 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2455 srcWidth
, srcHeight
, srcDepth
,
2456 srcFormat
, srcType
, srcAddr
,
2458 const GLubyte
*src
= tempImage
;
2459 GLint img
, row
, col
;
2462 for (img
= 0; img
< srcDepth
; img
++) {
2463 GLubyte
*dstRow
= dstSlices
[img
];
2464 for (row
= 0; row
< srcHeight
; row
++) {
2465 for (col
= 0; col
< srcWidth
; col
++) {
2466 dstRow
[col
] = src
[col
];
2468 dstRow
+= dstRowStride
;
2472 free((void *) tempImage
);
2480 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2483 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2485 const GLboolean littleEndian
= _mesa_little_endian();
2487 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2489 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2490 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2491 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2492 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2493 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2494 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2495 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2496 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2498 /* always just memcpy since no pixel transfer ops apply */
2499 memcpy_texture(ctx
, dims
,
2501 dstRowStride
, dstSlices
,
2502 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2503 srcAddr
, srcPacking
);
2505 /* Check if we need byte swapping */
2506 /* XXX the logic here _might_ be wrong */
2507 if (srcPacking
->SwapBytes
^
2508 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2509 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2512 for (img
= 0; img
< srcDepth
; img
++) {
2513 GLubyte
*dstRow
= dstSlices
[img
];
2514 for (row
= 0; row
< srcHeight
; row
++) {
2515 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2516 dstRow
+= dstRowStride
;
2524 * Store simple 8-bit/value stencil texture data.
2527 _mesa_texstore_s8(TEXSTORE_PARAMS
)
2529 ASSERT(dstFormat
== MESA_FORMAT_S8
);
2530 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
2532 if (!ctx
->_ImageTransferState
&&
2533 !srcPacking
->SwapBytes
&&
2534 baseInternalFormat
== srcFormat
&&
2535 srcType
== GL_UNSIGNED_BYTE
) {
2536 /* simple memcpy path */
2537 memcpy_texture(ctx
, dims
,
2539 dstRowStride
, dstSlices
,
2540 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2541 srcAddr
, srcPacking
);
2544 const GLint srcRowStride
2545 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2548 for (img
= 0; img
< srcDepth
; img
++) {
2549 GLubyte
*dstRow
= dstSlices
[img
];
2551 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2552 srcWidth
, srcHeight
,
2555 for (row
= 0; row
< srcHeight
; row
++) {
2556 GLubyte stencil
[MAX_WIDTH
];
2559 /* get the 8-bit stencil values */
2560 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2561 GL_UNSIGNED_BYTE
, /* dst type */
2562 stencil
, /* dst addr */
2563 srcType
, src
, srcPacking
,
2564 ctx
->_ImageTransferState
);
2565 /* merge stencil values into depth values */
2566 for (i
= 0; i
< srcWidth
; i
++)
2567 dstRow
[i
] = stencil
[i
];
2569 src
+= srcRowStride
;
2570 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
2581 * Store an image in any of the formats:
2582 * _mesa_texformat_rgba_float32
2583 * _mesa_texformat_rgb_float32
2584 * _mesa_texformat_alpha_float32
2585 * _mesa_texformat_luminance_float32
2586 * _mesa_texformat_luminance_alpha_float32
2587 * _mesa_texformat_intensity_float32
2590 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2592 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2593 const GLint components
= _mesa_components_in_format(baseFormat
);
2595 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2596 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2597 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
2598 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
2599 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
2600 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
2601 dstFormat
== MESA_FORMAT_R_FLOAT32
||
2602 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
2603 ASSERT(baseInternalFormat
== GL_RGBA
||
2604 baseInternalFormat
== GL_RGB
||
2605 baseInternalFormat
== GL_ALPHA
||
2606 baseInternalFormat
== GL_LUMINANCE
||
2607 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2608 baseInternalFormat
== GL_INTENSITY
||
2609 baseInternalFormat
== GL_RED
||
2610 baseInternalFormat
== GL_RG
);
2611 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
2613 if (!ctx
->_ImageTransferState
&&
2614 !srcPacking
->SwapBytes
&&
2615 baseInternalFormat
== srcFormat
&&
2616 baseInternalFormat
== baseFormat
&&
2617 srcType
== GL_FLOAT
) {
2618 /* simple memcpy path */
2619 memcpy_texture(ctx
, dims
,
2621 dstRowStride
, dstSlices
,
2622 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2623 srcAddr
, srcPacking
);
2627 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2630 srcWidth
, srcHeight
, srcDepth
,
2631 srcFormat
, srcType
, srcAddr
,
2633 ctx
->_ImageTransferState
);
2634 const GLfloat
*srcRow
= tempImage
;
2639 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2640 for (img
= 0; img
< srcDepth
; img
++) {
2641 GLubyte
*dstRow
= dstSlices
[img
];
2642 for (row
= 0; row
< srcHeight
; row
++) {
2643 memcpy(dstRow
, srcRow
, bytesPerRow
);
2644 dstRow
+= dstRowStride
;
2645 srcRow
+= srcWidth
* components
;
2649 free((void *) tempImage
);
2657 * As above, but store 16-bit floats.
2660 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2662 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2663 const GLint components
= _mesa_components_in_format(baseFormat
);
2665 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2666 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2667 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
2668 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
2669 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
2670 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
2671 dstFormat
== MESA_FORMAT_R_FLOAT16
||
2672 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
2673 ASSERT(baseInternalFormat
== GL_RGBA
||
2674 baseInternalFormat
== GL_RGB
||
2675 baseInternalFormat
== GL_ALPHA
||
2676 baseInternalFormat
== GL_LUMINANCE
||
2677 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2678 baseInternalFormat
== GL_INTENSITY
||
2679 baseInternalFormat
== GL_RED
||
2680 baseInternalFormat
== GL_RG
);
2681 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
2683 if (!ctx
->_ImageTransferState
&&
2684 !srcPacking
->SwapBytes
&&
2685 baseInternalFormat
== srcFormat
&&
2686 baseInternalFormat
== baseFormat
&&
2687 srcType
== GL_HALF_FLOAT_ARB
) {
2688 /* simple memcpy path */
2689 memcpy_texture(ctx
, dims
,
2691 dstRowStride
, dstSlices
,
2692 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2693 srcAddr
, srcPacking
);
2697 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2700 srcWidth
, srcHeight
, srcDepth
,
2701 srcFormat
, srcType
, srcAddr
,
2703 ctx
->_ImageTransferState
);
2704 const GLfloat
*src
= tempImage
;
2708 for (img
= 0; img
< srcDepth
; img
++) {
2709 GLubyte
*dstRow
= dstSlices
[img
];
2710 for (row
= 0; row
< srcHeight
; row
++) {
2711 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2713 for (i
= 0; i
< srcWidth
* components
; i
++) {
2714 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2716 dstRow
+= dstRowStride
;
2717 src
+= srcWidth
* components
;
2721 free((void *) tempImage
);
2727 /* non-normalized, signed int8 */
2729 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
2731 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2732 const GLint components
= _mesa_components_in_format(baseFormat
);
2734 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
2735 dstFormat
== MESA_FORMAT_RG_INT8
||
2736 dstFormat
== MESA_FORMAT_RGB_INT8
||
2737 dstFormat
== MESA_FORMAT_RGBA_INT8
||
2738 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
2739 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
2740 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
2741 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
2742 ASSERT(baseInternalFormat
== GL_RGBA
||
2743 baseInternalFormat
== GL_RGB
||
2744 baseInternalFormat
== GL_RG
||
2745 baseInternalFormat
== GL_RED
||
2746 baseInternalFormat
== GL_ALPHA
||
2747 baseInternalFormat
== GL_LUMINANCE
||
2748 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2749 baseInternalFormat
== GL_INTENSITY
);
2750 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
2752 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2753 * to integer formats.
2755 if (!srcPacking
->SwapBytes
&&
2756 baseInternalFormat
== srcFormat
&&
2757 srcType
== GL_BYTE
) {
2758 /* simple memcpy path */
2759 memcpy_texture(ctx
, dims
,
2761 dstRowStride
, dstSlices
,
2762 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2763 srcAddr
, srcPacking
);
2767 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2770 srcWidth
, srcHeight
, srcDepth
,
2774 const GLuint
*src
= tempImage
;
2778 for (img
= 0; img
< srcDepth
; img
++) {
2779 GLubyte
*dstRow
= dstSlices
[img
];
2780 for (row
= 0; row
< srcHeight
; row
++) {
2781 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
2783 for (i
= 0; i
< srcWidth
* components
; i
++) {
2784 dstTexel
[i
] = (GLbyte
) src
[i
];
2786 dstRow
+= dstRowStride
;
2787 src
+= srcWidth
* components
;
2791 free((void *) tempImage
);
2797 /* non-normalized, signed int16 */
2799 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
2801 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2802 const GLint components
= _mesa_components_in_format(baseFormat
);
2804 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
2805 dstFormat
== MESA_FORMAT_RG_INT16
||
2806 dstFormat
== MESA_FORMAT_RGB_INT16
||
2807 dstFormat
== MESA_FORMAT_RGBA_INT16
||
2808 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
2809 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
2810 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
2811 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
2812 ASSERT(baseInternalFormat
== GL_RGBA
||
2813 baseInternalFormat
== GL_RGB
||
2814 baseInternalFormat
== GL_RG
||
2815 baseInternalFormat
== GL_RED
||
2816 baseInternalFormat
== GL_ALPHA
||
2817 baseInternalFormat
== GL_LUMINANCE
||
2818 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2819 baseInternalFormat
== GL_INTENSITY
);
2820 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
2822 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2823 * to integer formats.
2825 if (!srcPacking
->SwapBytes
&&
2826 baseInternalFormat
== srcFormat
&&
2827 srcType
== GL_SHORT
) {
2828 /* simple memcpy path */
2829 memcpy_texture(ctx
, dims
,
2831 dstRowStride
, dstSlices
,
2832 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2833 srcAddr
, srcPacking
);
2837 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2840 srcWidth
, srcHeight
, srcDepth
,
2844 const GLuint
*src
= tempImage
;
2848 for (img
= 0; img
< srcDepth
; img
++) {
2849 GLubyte
*dstRow
= dstSlices
[img
];
2850 for (row
= 0; row
< srcHeight
; row
++) {
2851 GLshort
*dstTexel
= (GLshort
*) dstRow
;
2853 for (i
= 0; i
< srcWidth
* components
; i
++) {
2854 dstTexel
[i
] = (GLint
) src
[i
];
2856 dstRow
+= dstRowStride
;
2857 src
+= srcWidth
* components
;
2861 free((void *) tempImage
);
2867 /* non-normalized, signed int32 */
2869 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
2871 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2872 const GLint components
= _mesa_components_in_format(baseFormat
);
2874 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
2875 dstFormat
== MESA_FORMAT_RG_INT32
||
2876 dstFormat
== MESA_FORMAT_RGB_INT32
||
2877 dstFormat
== MESA_FORMAT_RGBA_INT32
||
2878 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
2879 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
2880 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
2881 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
2882 ASSERT(baseInternalFormat
== GL_RGBA
||
2883 baseInternalFormat
== GL_RGB
||
2884 baseInternalFormat
== GL_RG
||
2885 baseInternalFormat
== GL_RED
||
2886 baseInternalFormat
== GL_ALPHA
||
2887 baseInternalFormat
== GL_LUMINANCE
||
2888 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2889 baseInternalFormat
== GL_INTENSITY
);
2890 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
2892 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2893 * to integer formats.
2895 if (!srcPacking
->SwapBytes
&&
2896 baseInternalFormat
== srcFormat
&&
2897 srcType
== GL_INT
) {
2898 /* simple memcpy path */
2899 memcpy_texture(ctx
, dims
,
2901 dstRowStride
, dstSlices
,
2902 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2903 srcAddr
, srcPacking
);
2907 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2910 srcWidth
, srcHeight
, srcDepth
,
2914 const GLuint
*src
= tempImage
;
2918 for (img
= 0; img
< srcDepth
; img
++) {
2919 GLubyte
*dstRow
= dstSlices
[img
];
2920 for (row
= 0; row
< srcHeight
; row
++) {
2921 GLint
*dstTexel
= (GLint
*) dstRow
;
2923 for (i
= 0; i
< srcWidth
* components
; i
++) {
2924 dstTexel
[i
] = (GLint
) src
[i
];
2926 dstRow
+= dstRowStride
;
2927 src
+= srcWidth
* components
;
2931 free((void *) tempImage
);
2937 /* non-normalized, unsigned int8 */
2939 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
2941 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2942 const GLint components
= _mesa_components_in_format(baseFormat
);
2944 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
2945 dstFormat
== MESA_FORMAT_RG_UINT8
||
2946 dstFormat
== MESA_FORMAT_RGB_UINT8
||
2947 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
2948 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
2949 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
2950 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
2951 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
2952 ASSERT(baseInternalFormat
== GL_RGBA
||
2953 baseInternalFormat
== GL_RGB
||
2954 baseInternalFormat
== GL_RG
||
2955 baseInternalFormat
== GL_RED
||
2956 baseInternalFormat
== GL_ALPHA
||
2957 baseInternalFormat
== GL_LUMINANCE
||
2958 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2959 baseInternalFormat
== GL_INTENSITY
);
2960 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
2962 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2963 * to integer formats.
2965 if (!srcPacking
->SwapBytes
&&
2966 baseInternalFormat
== srcFormat
&&
2967 srcType
== GL_UNSIGNED_BYTE
) {
2968 /* simple memcpy path */
2969 memcpy_texture(ctx
, dims
,
2971 dstRowStride
, dstSlices
,
2972 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2973 srcAddr
, srcPacking
);
2977 const GLuint
*tempImage
=
2978 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
2979 srcWidth
, srcHeight
, srcDepth
,
2980 srcFormat
, srcType
, srcAddr
, srcPacking
);
2981 const GLuint
*src
= tempImage
;
2985 for (img
= 0; img
< srcDepth
; img
++) {
2986 GLubyte
*dstRow
= dstSlices
[img
];
2987 for (row
= 0; row
< srcHeight
; row
++) {
2988 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
2990 for (i
= 0; i
< srcWidth
* components
; i
++) {
2991 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
2993 dstRow
+= dstRowStride
;
2994 src
+= srcWidth
* components
;
2998 free((void *) tempImage
);
3004 /* non-normalized, unsigned int16 */
3006 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3008 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3009 const GLint components
= _mesa_components_in_format(baseFormat
);
3011 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3012 dstFormat
== MESA_FORMAT_RG_UINT16
||
3013 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3014 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3015 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3016 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3017 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3018 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3019 ASSERT(baseInternalFormat
== GL_RGBA
||
3020 baseInternalFormat
== GL_RGB
||
3021 baseInternalFormat
== GL_RG
||
3022 baseInternalFormat
== GL_RED
||
3023 baseInternalFormat
== GL_ALPHA
||
3024 baseInternalFormat
== GL_LUMINANCE
||
3025 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3026 baseInternalFormat
== GL_INTENSITY
);
3027 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3029 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3030 * to integer formats.
3032 if (!srcPacking
->SwapBytes
&&
3033 baseInternalFormat
== srcFormat
&&
3034 srcType
== GL_UNSIGNED_SHORT
) {
3035 /* simple memcpy path */
3036 memcpy_texture(ctx
, dims
,
3038 dstRowStride
, dstSlices
,
3039 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3040 srcAddr
, srcPacking
);
3044 const GLuint
*tempImage
=
3045 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3046 srcWidth
, srcHeight
, srcDepth
,
3047 srcFormat
, srcType
, srcAddr
, srcPacking
);
3048 const GLuint
*src
= tempImage
;
3052 for (img
= 0; img
< srcDepth
; img
++) {
3053 GLubyte
*dstRow
= dstSlices
[img
];
3054 for (row
= 0; row
< srcHeight
; row
++) {
3055 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3057 for (i
= 0; i
< srcWidth
* components
; i
++) {
3058 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3060 dstRow
+= dstRowStride
;
3061 src
+= srcWidth
* components
;
3065 free((void *) tempImage
);
3071 /* non-normalized, unsigned int32 */
3073 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3075 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3076 const GLint components
= _mesa_components_in_format(baseFormat
);
3078 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3079 dstFormat
== MESA_FORMAT_RG_UINT32
||
3080 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3081 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3082 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3083 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3084 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3085 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3086 ASSERT(baseInternalFormat
== GL_RGBA
||
3087 baseInternalFormat
== GL_RGB
||
3088 baseInternalFormat
== GL_RG
||
3089 baseInternalFormat
== GL_RED
||
3090 baseInternalFormat
== GL_ALPHA
||
3091 baseInternalFormat
== GL_LUMINANCE
||
3092 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3093 baseInternalFormat
== GL_INTENSITY
);
3094 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3096 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3097 * to integer formats.
3099 if (!srcPacking
->SwapBytes
&&
3100 baseInternalFormat
== srcFormat
&&
3101 srcType
== GL_UNSIGNED_INT
) {
3102 /* simple memcpy path */
3103 memcpy_texture(ctx
, dims
,
3105 dstRowStride
, dstSlices
,
3106 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3107 srcAddr
, srcPacking
);
3111 const GLuint
*tempImage
=
3112 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3113 srcWidth
, srcHeight
, srcDepth
,
3114 srcFormat
, srcType
, srcAddr
, srcPacking
);
3115 const GLuint
*src
= tempImage
;
3119 for (img
= 0; img
< srcDepth
; img
++) {
3120 GLubyte
*dstRow
= dstSlices
[img
];
3121 for (row
= 0; row
< srcHeight
; row
++) {
3122 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3124 for (i
= 0; i
< srcWidth
* components
; i
++) {
3125 dstTexel
[i
] = src
[i
];
3127 dstRow
+= dstRowStride
;
3128 src
+= srcWidth
* components
;
3132 free((void *) tempImage
);
3138 _mesa_texstore_null(TEXSTORE_PARAMS
)
3140 (void) ctx
; (void) dims
;
3141 (void) baseInternalFormat
;
3143 (void) dstRowStride
; (void) dstSlices
,
3144 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3145 (void) srcFormat
; (void) srcType
;
3149 /* should never happen */
3150 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3156 * Return the StoreTexImageFunc pointer to store an image in the given format.
3158 static StoreTexImageFunc
3159 _mesa_get_texstore_func(gl_format format
)
3161 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3162 static GLboolean initialized
= GL_FALSE
;
3165 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
3167 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
3168 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
3169 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
3170 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
3171 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
3172 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
3173 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
3174 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
3175 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
3176 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
3177 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
3178 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
3179 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
3180 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
3181 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
3182 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
3183 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
3184 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
3185 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
3186 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
3187 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
3188 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
3189 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
3190 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
3191 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
3192 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
3193 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
3194 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
3195 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
3196 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
3197 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
3198 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
3199 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
3200 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
3201 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
3202 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
3203 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3204 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3205 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
3206 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
3207 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3208 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3209 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
3210 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
3211 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3212 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3213 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
3214 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
3215 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
3216 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
3218 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
3219 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
3220 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
3221 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
3222 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
3223 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
3225 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
3226 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
3227 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
3228 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
3229 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
3230 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
3232 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
3233 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
3234 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
3235 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
3236 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
3237 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
3239 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
3240 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
3241 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
3242 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
3243 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
3244 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
3246 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
3247 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
3248 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
3249 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
3250 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
3251 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
3253 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
3254 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
3255 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
3256 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
3257 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
3258 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
3260 initialized
= GL_TRUE
;
3263 ASSERT(table
[format
]);
3264 return table
[format
];
3269 * Store user data into texture memory.
3270 * Called via glTex[Sub]Image1/2/3D()
3273 _mesa_texstore(TEXSTORE_PARAMS
)
3275 StoreTexImageFunc storeImage
;
3278 storeImage
= _mesa_get_texstore_func(dstFormat
);
3280 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3282 dstRowStride
, dstSlices
,
3283 srcWidth
, srcHeight
, srcDepth
,
3284 srcFormat
, srcType
, srcAddr
, srcPacking
);
3290 * Normally, we'll only _write_ texel data to a texture when we map it.
3291 * But if the user is providing depth or stencil values and the texture
3292 * image is a combined depth/stencil format, we'll actually read from
3293 * the texture buffer too (in order to insert the depth or stencil values.
3294 * \param userFormat the user-provided image format
3295 * \param texFormat the destination texture format
3298 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
3300 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
3305 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
3307 * The source of the image data may be user memory or a PBO. In the later
3308 * case, we'll map the PBO, copy from it, then unmap it.
3311 store_texsubimage(struct gl_context
*ctx
,
3312 struct gl_texture_image
*texImage
,
3313 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3314 GLint width
, GLint height
, GLint depth
,
3315 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3316 const struct gl_pixelstore_attrib
*packing
,
3320 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
3321 const GLenum target
= texImage
->TexObject
->Target
;
3322 GLboolean success
= GL_FALSE
;
3323 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
3324 GLint srcImageStride
= 0;
3327 assert(xoffset
+ width
<= texImage
->Width
);
3328 assert(yoffset
+ height
<= texImage
->Height
);
3329 assert(zoffset
+ depth
<= texImage
->Depth
);
3342 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3343 src
= (const GLubyte
*)
3344 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
3345 format
, type
, pixels
, packing
, caller
);
3349 /* compute slice info (and do some sanity checks) */
3352 case GL_TEXTURE_CUBE_MAP
:
3353 /* one image slice, nothing special needs to be done */
3356 assert(height
== 1);
3358 assert(yoffset
== 0);
3359 assert(zoffset
== 0);
3362 /* we'll store 3D images as a series of slices */
3364 sliceOffset
= zoffset
;
3365 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
3369 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
3373 assert(numSlices
== 1 || srcImageStride
!= 0);
3375 for (slice
= 0; slice
< numSlices
; slice
++) {
3379 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
3380 slice
+ sliceOffset
,
3381 xoffset
, yoffset
, width
, height
,
3382 mapMode
, &dstMap
, &dstRowStride
);
3384 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
3385 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
3386 * used for 3D images.
3388 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
3389 texImage
->TexFormat
,
3392 width
, height
, 1, /* w, h, d */
3393 format
, type
, src
, packing
);
3395 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
3398 src
+= srcImageStride
;
3405 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
3407 _mesa_unmap_teximage_pbo(ctx
, packing
);
3413 * This is the fallback for Driver.TexImage1D().
3416 _mesa_store_teximage1d(struct gl_context
*ctx
,
3417 struct gl_texture_image
*texImage
,
3418 GLint internalFormat
,
3419 GLint width
, GLint border
,
3420 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3421 const struct gl_pixelstore_attrib
*packing
)
3426 /* allocate storage for texture data */
3427 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
3429 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3433 store_texsubimage(ctx
, texImage
,
3434 0, 0, 0, width
, 1, 1,
3435 format
, type
, pixels
, packing
, "glTexImage1D");
3440 * This is the fallback for Driver.TexImage2D().
3443 _mesa_store_teximage2d(struct gl_context
*ctx
,
3444 struct gl_texture_image
*texImage
,
3445 GLint internalFormat
,
3446 GLint width
, GLint height
, GLint border
,
3447 GLenum format
, GLenum type
, const void *pixels
,
3448 const struct gl_pixelstore_attrib
*packing
)
3450 if (width
== 0 || height
== 0)
3453 /* allocate storage for texture data */
3454 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
3455 width
, height
, 1)) {
3456 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3460 store_texsubimage(ctx
, texImage
,
3461 0, 0, 0, width
, height
, 1,
3462 format
, type
, pixels
, packing
, "glTexImage2D");
3468 * This is the fallback for Driver.TexImage3D().
3471 _mesa_store_teximage3d(struct gl_context
*ctx
,
3472 struct gl_texture_image
*texImage
,
3473 GLint internalFormat
,
3474 GLint width
, GLint height
, GLint depth
, GLint border
,
3475 GLenum format
, GLenum type
, const void *pixels
,
3476 const struct gl_pixelstore_attrib
*packing
)
3478 if (width
== 0 || height
== 0 || depth
== 0)
3481 /* allocate storage for texture data */
3482 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
3483 width
, height
, depth
)) {
3484 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3488 store_texsubimage(ctx
, texImage
,
3489 0, 0, 0, width
, height
, depth
,
3490 format
, type
, pixels
, packing
, "glTexImage3D");
3497 * This is the fallback for Driver.TexSubImage1D().
3500 _mesa_store_texsubimage1d(struct gl_context
*ctx
,
3501 struct gl_texture_image
*texImage
,
3502 GLint xoffset
, GLint width
,
3503 GLenum format
, GLenum type
, const void *pixels
,
3504 const struct gl_pixelstore_attrib
*packing
)
3506 store_texsubimage(ctx
, texImage
,
3507 xoffset
, 0, 0, width
, 1, 1,
3508 format
, type
, pixels
, packing
, "glTexSubImage1D");
3514 * This is the fallback for Driver.TexSubImage2D().
3517 _mesa_store_texsubimage2d(struct gl_context
*ctx
,
3518 struct gl_texture_image
*texImage
,
3519 GLint xoffset
, GLint yoffset
,
3520 GLint width
, GLint height
,
3521 GLenum format
, GLenum type
, const void *pixels
,
3522 const struct gl_pixelstore_attrib
*packing
)
3524 store_texsubimage(ctx
, texImage
,
3525 xoffset
, yoffset
, 0, width
, height
, 1,
3526 format
, type
, pixels
, packing
, "glTexSubImage2D");
3531 * This is the fallback for Driver.TexSubImage3D().
3534 _mesa_store_texsubimage3d(struct gl_context
*ctx
,
3535 struct gl_texture_image
*texImage
,
3536 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3537 GLint width
, GLint height
, GLint depth
,
3538 GLenum format
, GLenum type
, const void *pixels
,
3539 const struct gl_pixelstore_attrib
*packing
)
3541 store_texsubimage(ctx
, texImage
,
3542 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3543 format
, type
, pixels
, packing
, "glTexSubImage3D");