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, convolution!, 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
:
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),
179 MAP4(0, ZERO
, ZERO
, ONE
),
185 MAP4(ZERO
, 0, ZERO
, ONE
),
191 MAP4(ZERO
, ZERO
, 0, ONE
),
217 * Convert a GL image format enum to an IDX_* value (see above).
220 get_map_idx(GLenum value
)
223 case GL_LUMINANCE
: return IDX_LUMINANCE
;
224 case GL_ALPHA
: return IDX_ALPHA
;
225 case GL_INTENSITY
: return IDX_INTENSITY
;
226 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
227 case GL_RGB
: return IDX_RGB
;
228 case GL_RGBA
: return IDX_RGBA
;
229 case GL_RED
: return IDX_RED
;
230 case GL_GREEN
: return IDX_GREEN
;
231 case GL_BLUE
: return IDX_BLUE
;
232 case GL_BGR
: return IDX_BGR
;
233 case GL_BGRA
: return IDX_BGRA
;
234 case GL_ABGR_EXT
: return IDX_ABGR
;
236 _mesa_problem(NULL
, "Unexpected inFormat");
243 * When promoting texture formats (see below) we need to compute the
244 * mapping of dest components back to source components.
245 * This function does that.
246 * \param inFormat the incoming format of the texture
247 * \param outFormat the final texture format
248 * \return map[6] a full 6-component map
251 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
254 const int inFmt
= get_map_idx(inFormat
);
255 const int outFmt
= get_map_idx(outFormat
);
256 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
257 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
260 for (i
= 0; i
< 4; i
++)
261 map
[i
] = in2rgba
[rgba2out
[i
]];
267 _mesa_printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
268 inFormat, _mesa_lookup_enum_by_nr(inFormat),
269 outFormat, _mesa_lookup_enum_by_nr(outFormat),
280 #if !FEATURE_convolve
282 _mesa_adjust_image_for_convolution(GLcontext
*ctx
, GLuint dims
,
283 GLsizei
*srcWidth
, GLsizei
*srcHeight
)
291 * Make a temporary (color) texture image with GLfloat components.
292 * Apply all needed pixel unpacking and pixel transfer operations.
293 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
294 * Suppose the user specifies GL_LUMINANCE as the internal texture format
295 * but the graphics hardware doesn't support luminance textures. So, might
296 * use an RGB hardware format instead.
297 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
299 * \param ctx the rendering context
300 * \param dims image dimensions: 1, 2 or 3
301 * \param logicalBaseFormat basic texture derived from the user's
302 * internal texture format value
303 * \param textureBaseFormat the actual basic format of the texture
304 * \param srcWidth source image width
305 * \param srcHeight source image height
306 * \param srcDepth source image depth
307 * \param srcFormat source image format
308 * \param srcType source image type
309 * \param srcAddr source image address
310 * \param srcPacking source image pixel packing
311 * \return resulting image with format = textureBaseFormat and type = GLfloat.
314 make_temp_float_image(GLcontext
*ctx
, GLuint dims
,
315 GLenum logicalBaseFormat
,
316 GLenum textureBaseFormat
,
317 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
318 GLenum srcFormat
, GLenum srcType
,
319 const GLvoid
*srcAddr
,
320 const struct gl_pixelstore_attrib
*srcPacking
)
322 GLuint transferOps
= ctx
->_ImageTransferState
;
325 ASSERT(dims
>= 1 && dims
<= 3);
327 ASSERT(logicalBaseFormat
== GL_RGBA
||
328 logicalBaseFormat
== GL_RGB
||
329 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
330 logicalBaseFormat
== GL_LUMINANCE
||
331 logicalBaseFormat
== GL_ALPHA
||
332 logicalBaseFormat
== GL_INTENSITY
||
333 logicalBaseFormat
== GL_COLOR_INDEX
||
334 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
336 ASSERT(textureBaseFormat
== GL_RGBA
||
337 textureBaseFormat
== GL_RGB
||
338 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
339 textureBaseFormat
== GL_LUMINANCE
||
340 textureBaseFormat
== GL_ALPHA
||
341 textureBaseFormat
== GL_INTENSITY
||
342 textureBaseFormat
== GL_COLOR_INDEX
||
343 textureBaseFormat
== GL_DEPTH_COMPONENT
);
345 /* conventional color image */
347 if ((dims
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
348 (dims
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
349 (dims
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
350 /* need image convolution */
351 const GLuint preConvTransferOps
352 = (transferOps
& IMAGE_PRE_CONVOLUTION_BITS
) | IMAGE_CLAMP_BIT
;
353 const GLuint postConvTransferOps
354 = (transferOps
& IMAGE_POST_CONVOLUTION_BITS
) | IMAGE_CLAMP_BIT
;
356 GLint convWidth
, convHeight
;
359 /* pre-convolution image buffer (3D) */
360 tempImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
361 * 4 * sizeof(GLfloat
));
365 /* post-convolution image buffer (2D) */
366 convImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
367 * 4 * sizeof(GLfloat
));
369 _mesa_free(tempImage
);
373 /* loop over 3D image slices */
374 for (img
= 0; img
< srcDepth
; img
++) {
375 GLfloat
*dst
= tempImage
+ img
* (srcWidth
* srcHeight
* 4);
377 /* unpack and do transfer ops up to convolution */
378 for (row
= 0; row
< srcHeight
; row
++) {
379 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
380 srcAddr
, srcWidth
, srcHeight
,
381 srcFormat
, srcType
, img
, row
, 0);
382 _mesa_unpack_color_span_float(ctx
, srcWidth
, GL_RGBA
, dst
,
383 srcFormat
, srcType
, src
,
389 /* size after optional convolution */
390 convWidth
= srcWidth
;
391 convHeight
= srcHeight
;
396 GLfloat
*src
= tempImage
+ img
* (srcWidth
* srcHeight
* 4);
398 ASSERT(ctx
->Pixel
.Convolution1DEnabled
);
399 _mesa_convolve_1d_image(ctx
, &convWidth
, src
, convImage
);
402 if (ctx
->Pixel
.Convolution2DEnabled
) {
403 _mesa_convolve_2d_image(ctx
, &convWidth
, &convHeight
,
407 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
408 _mesa_convolve_sep_image(ctx
, &convWidth
, &convHeight
,
414 /* do post-convolution transfer and pack into tempImage */
416 const GLint logComponents
417 = _mesa_components_in_format(logicalBaseFormat
);
418 const GLfloat
*src
= convImage
;
419 GLfloat
*dst
= tempImage
+ img
* (convWidth
* convHeight
* 4);
420 for (row
= 0; row
< convHeight
; row
++) {
421 _mesa_pack_rgba_span_float(ctx
, convWidth
,
422 (GLfloat (*)[4]) src
,
423 logicalBaseFormat
, GL_FLOAT
,
424 dst
, &ctx
->DefaultPacking
,
425 postConvTransferOps
);
426 src
+= convWidth
* 4;
427 dst
+= convWidth
* logComponents
;
430 } /* loop over 3D image slices */
432 _mesa_free(convImage
);
434 /* might need these below */
435 srcWidth
= convWidth
;
436 srcHeight
= convHeight
;
440 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
441 const GLint srcStride
=
442 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
446 tempImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
447 * components
* sizeof(GLfloat
));
452 for (img
= 0; img
< srcDepth
; img
++) {
454 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
458 for (row
= 0; row
< srcHeight
; row
++) {
459 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
460 dst
, srcFormat
, srcType
, src
,
461 srcPacking
, transferOps
);
462 dst
+= srcWidth
* components
;
468 if (logicalBaseFormat
!= textureBaseFormat
) {
470 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
471 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
476 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
477 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
478 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
480 /* The actual texture format should have at least as many components
481 * as the logical texture format.
483 ASSERT(texComponents
>= logComponents
);
485 newImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
486 * texComponents
* sizeof(GLfloat
));
488 _mesa_free(tempImage
);
492 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
494 n
= srcWidth
* srcHeight
* srcDepth
;
495 for (i
= 0; i
< n
; i
++) {
497 for (k
= 0; k
< texComponents
; k
++) {
500 newImage
[i
* texComponents
+ k
] = 0.0F
;
502 newImage
[i
* texComponents
+ k
] = 1.0F
;
504 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
508 _mesa_free(tempImage
);
509 tempImage
= newImage
;
517 * Make a temporary (color) texture image with GLchan components.
518 * Apply all needed pixel unpacking and pixel transfer operations.
519 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
520 * Suppose the user specifies GL_LUMINANCE as the internal texture format
521 * but the graphics hardware doesn't support luminance textures. So, might
522 * use an RGB hardware format instead.
523 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
525 * \param ctx the rendering context
526 * \param dims image dimensions: 1, 2 or 3
527 * \param logicalBaseFormat basic texture derived from the user's
528 * internal texture format value
529 * \param textureBaseFormat the actual basic format of the texture
530 * \param srcWidth source image width
531 * \param srcHeight source image height
532 * \param srcDepth source image depth
533 * \param srcFormat source image format
534 * \param srcType source image type
535 * \param srcAddr source image address
536 * \param srcPacking source image pixel packing
537 * \return resulting image with format = textureBaseFormat and type = GLchan.
540 _mesa_make_temp_chan_image(GLcontext
*ctx
, GLuint dims
,
541 GLenum logicalBaseFormat
,
542 GLenum textureBaseFormat
,
543 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
544 GLenum srcFormat
, GLenum srcType
,
545 const GLvoid
*srcAddr
,
546 const struct gl_pixelstore_attrib
*srcPacking
)
548 GLuint transferOps
= ctx
->_ImageTransferState
;
549 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
550 GLboolean freeSrcImage
= GL_FALSE
;
552 GLchan
*tempImage
, *dst
;
554 ASSERT(dims
>= 1 && dims
<= 3);
556 ASSERT(logicalBaseFormat
== GL_RGBA
||
557 logicalBaseFormat
== GL_RGB
||
558 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
559 logicalBaseFormat
== GL_LUMINANCE
||
560 logicalBaseFormat
== GL_ALPHA
||
561 logicalBaseFormat
== GL_INTENSITY
);
563 ASSERT(textureBaseFormat
== GL_RGBA
||
564 textureBaseFormat
== GL_RGB
||
565 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
566 textureBaseFormat
== GL_LUMINANCE
||
567 textureBaseFormat
== GL_ALPHA
||
568 textureBaseFormat
== GL_INTENSITY
);
571 if ((dims
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
572 (dims
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
573 (dims
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
574 /* get convolved image */
575 GLfloat
*convImage
= make_temp_float_image(ctx
, dims
,
578 srcWidth
, srcHeight
, srcDepth
,
580 srcAddr
, srcPacking
);
583 /* the convolved image is our new source image */
585 srcFormat
= logicalBaseFormat
;
587 srcPacking
= &ctx
->DefaultPacking
;
588 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
590 freeSrcImage
= GL_TRUE
;
594 /* unpack and transfer the source image */
595 tempImage
= (GLchan
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
596 * components
* sizeof(GLchan
));
599 _mesa_free((void *) srcAddr
);
605 for (img
= 0; img
< srcDepth
; img
++) {
606 const GLint srcStride
=
607 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
609 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
613 for (row
= 0; row
< srcHeight
; row
++) {
614 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
615 srcFormat
, srcType
, src
, srcPacking
,
617 dst
+= srcWidth
* components
;
622 /* If we made a temporary image for convolution, free it here */
624 _mesa_free((void *) srcAddr
);
627 if (logicalBaseFormat
!= textureBaseFormat
) {
628 /* one more conversion step */
629 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
630 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
635 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
636 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
637 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
639 /* The actual texture format should have at least as many components
640 * as the logical texture format.
642 ASSERT(texComponents
>= logComponents
);
644 newImage
= (GLchan
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
645 * texComponents
* sizeof(GLchan
));
647 _mesa_free(tempImage
);
651 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
653 n
= srcWidth
* srcHeight
* srcDepth
;
654 for (i
= 0; i
< n
; i
++) {
656 for (k
= 0; k
< texComponents
; k
++) {
659 newImage
[i
* texComponents
+ k
] = 0;
661 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
663 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
667 _mesa_free(tempImage
);
668 tempImage
= newImage
;
676 * Copy GLubyte pixels from <src> to <dst> with swizzling.
677 * \param dst destination pixels
678 * \param dstComponents number of color components in destination pixels
679 * \param src source pixels
680 * \param srcComponents number of color components in source pixels
681 * \param map the swizzle mapping. map[X] says where to find the X component
682 * in the source image's pixels. For example, if the source image
683 * is GL_BGRA and X = red, map[0] yields 2.
684 * \param count number of pixels to copy/swizzle.
687 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
688 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
690 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
693 for (i = 0; i < count; i++) { \
695 if (srcComps == 4) { \
696 COPY_4UBV(tmp, src); \
699 for (j = 0; j < srcComps; j++) { \
704 for (j = 0; j < dstComps; j++) { \
705 dst[j] = tmp[map[j]]; \
716 ASSERT(srcComponents
<= 4);
717 ASSERT(dstComponents
<= 4);
719 switch (dstComponents
) {
721 switch (srcComponents
) {
723 SWZ_CPY(dst
, src
, count
, 4, 4);
726 SWZ_CPY(dst
, src
, count
, 4, 3);
729 SWZ_CPY(dst
, src
, count
, 4, 2);
732 SWZ_CPY(dst
, src
, count
, 4, 1);
739 switch (srcComponents
) {
741 SWZ_CPY(dst
, src
, count
, 3, 4);
744 SWZ_CPY(dst
, src
, count
, 3, 3);
747 SWZ_CPY(dst
, src
, count
, 3, 2);
750 SWZ_CPY(dst
, src
, count
, 3, 1);
757 switch (srcComponents
) {
759 SWZ_CPY(dst
, src
, count
, 2, 4);
762 SWZ_CPY(dst
, src
, count
, 2, 3);
765 SWZ_CPY(dst
, src
, count
, 2, 2);
768 SWZ_CPY(dst
, src
, count
, 2, 1);
775 switch (srcComponents
) {
777 SWZ_CPY(dst
, src
, count
, 1, 4);
780 SWZ_CPY(dst
, src
, count
, 1, 3);
783 SWZ_CPY(dst
, src
, count
, 1, 2);
786 SWZ_CPY(dst
, src
, count
, 1, 1);
800 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
801 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
803 /* Deal with the _REV input types:
805 static const GLubyte
*
806 type_mapping( GLenum srcType
)
810 case GL_UNSIGNED_BYTE
:
812 case GL_UNSIGNED_INT_8_8_8_8
:
813 return _mesa_little_endian() ? map_3210
: map_identity
;
814 case GL_UNSIGNED_INT_8_8_8_8_REV
:
815 return _mesa_little_endian() ? map_identity
: map_3210
;
821 /* Mapping required if input type is
823 static const GLubyte
*
824 byteswap_mapping( GLboolean swapBytes
,
832 case GL_UNSIGNED_BYTE
:
834 case GL_UNSIGNED_INT_8_8_8_8
:
835 case GL_UNSIGNED_INT_8_8_8_8_REV
:
845 * Transfer a GLubyte texture image with component swizzling.
848 _mesa_swizzle_ubyte_image(GLcontext
*ctx
,
853 GLenum baseInternalFormat
,
855 const GLubyte
*rgba2dst
,
856 GLuint dstComponents
,
859 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
861 const GLuint
*dstImageOffsets
,
863 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
864 const GLvoid
*srcAddr
,
865 const struct gl_pixelstore_attrib
*srcPacking
)
867 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
868 const GLubyte
*srctype2ubyte
, *swap
;
869 GLubyte map
[4], src2base
[6], base2rgba
[6];
871 const GLint srcRowStride
=
872 _mesa_image_row_stride(srcPacking
, srcWidth
,
873 srcFormat
, GL_UNSIGNED_BYTE
);
874 const GLint srcImageStride
875 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
877 const GLubyte
*srcImage
878 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
879 srcWidth
, srcHeight
, srcFormat
,
880 GL_UNSIGNED_BYTE
, 0, 0, 0);
884 /* Translate from src->baseInternal->GL_RGBA->dst. This will
885 * correctly deal with RGBA->RGB->RGBA conversions where the final
886 * A value must be 0xff regardless of the incoming alpha values.
888 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
889 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
890 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
891 srctype2ubyte
= type_mapping(srcType
);
894 for (i
= 0; i
< 4; i
++)
895 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
897 /* _mesa_printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
899 if (srcComponents
== dstComponents
&&
900 srcRowStride
== dstRowStride
&&
901 srcRowStride
== srcWidth
* srcComponents
&&
903 /* 1 and 2D images only */
904 GLubyte
*dstImage
= (GLubyte
*) dstAddr
905 + dstYoffset
* dstRowStride
906 + dstXoffset
* dstComponents
;
907 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
908 srcWidth
* srcHeight
);
912 for (img
= 0; img
< srcDepth
; img
++) {
913 const GLubyte
*srcRow
= srcImage
;
914 GLubyte
*dstRow
= (GLubyte
*) dstAddr
915 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
916 + dstYoffset
* dstRowStride
917 + dstXoffset
* dstComponents
;
918 for (row
= 0; row
< srcHeight
; row
++) {
919 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
920 dstRow
+= dstRowStride
;
921 srcRow
+= srcRowStride
;
923 srcImage
+= srcImageStride
;
930 * Teximage storage routine for when a simple memcpy will do.
931 * No pixel transfer operations or special texel encodings allowed.
932 * 1D, 2D and 3D images supported.
935 memcpy_texture(GLcontext
*ctx
,
939 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
941 const GLuint
*dstImageOffsets
,
942 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
943 GLenum srcFormat
, GLenum srcType
,
944 const GLvoid
*srcAddr
,
945 const struct gl_pixelstore_attrib
*srcPacking
)
947 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
949 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
950 srcWidth
, srcHeight
, srcFormat
, srcType
);
951 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
952 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
953 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
954 const GLint bytesPerRow
= srcWidth
* texelBytes
;
957 /* XXX update/re-enable for dstImageOffsets array */
958 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
959 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
960 GLubyte
*dstImage
= (GLubyte
*) dstAddr
961 + dstZoffset
* dstImageStride
962 + dstYoffset
* dstRowStride
963 + dstXoffset
* texelBytes
;
965 if (dstRowStride
== srcRowStride
&&
966 dstRowStride
== bytesPerRow
&&
967 ((dstImageStride
== srcImageStride
&&
968 dstImageStride
== bytesPerImage
) ||
971 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
976 for (img
= 0; img
< srcDepth
; img
++) {
977 const GLubyte
*srcRow
= srcImage
;
978 GLubyte
*dstRow
= dstImage
;
979 for (row
= 0; row
< srcHeight
; row
++) {
980 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
981 dstRow
+= dstRowStride
;
982 srcRow
+= srcRowStride
;
984 srcImage
+= srcImageStride
;
985 dstImage
+= dstImageStride
;
991 for (img
= 0; img
< srcDepth
; img
++) {
992 const GLubyte
*srcRow
= srcImage
;
993 GLubyte
*dstRow
= (GLubyte
*) dstAddr
994 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
995 + dstYoffset
* dstRowStride
996 + dstXoffset
* texelBytes
;
997 for (row
= 0; row
< srcHeight
; row
++) {
998 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
999 dstRow
+= dstRowStride
;
1000 srcRow
+= srcRowStride
;
1002 srcImage
+= srcImageStride
;
1009 * Store a 32-bit integer depth component texture image.
1012 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1014 const GLuint depthScale
= 0xffffffff;
1015 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1017 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1018 ASSERT(texelBytes
== sizeof(GLuint
));
1020 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1021 ctx
->Pixel
.DepthBias
== 0.0f
&&
1022 !srcPacking
->SwapBytes
&&
1023 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1024 srcFormat
== GL_DEPTH_COMPONENT
&&
1025 srcType
== GL_UNSIGNED_INT
) {
1026 /* simple memcpy path */
1027 memcpy_texture(ctx
, dims
,
1028 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1031 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1032 srcAddr
, srcPacking
);
1037 for (img
= 0; img
< srcDepth
; img
++) {
1038 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1039 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1040 + dstYoffset
* dstRowStride
1041 + dstXoffset
* texelBytes
;
1042 for (row
= 0; row
< srcHeight
; row
++) {
1043 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1044 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1045 _mesa_unpack_depth_span(ctx
, srcWidth
,
1046 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1047 depthScale
, srcType
, src
, srcPacking
);
1048 dstRow
+= dstRowStride
;
1057 * Store a 24-bit integer depth component texture image.
1060 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1062 const GLuint depthScale
= 0xffffff;
1063 const GLuint texelBytes
= 4;
1066 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1071 for (img
= 0; img
< srcDepth
; img
++) {
1072 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1073 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1074 + dstYoffset
* dstRowStride
1075 + dstXoffset
* texelBytes
;
1076 for (row
= 0; row
< srcHeight
; row
++) {
1077 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1078 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1079 _mesa_unpack_depth_span(ctx
, srcWidth
,
1080 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1081 depthScale
, srcType
, src
, srcPacking
);
1082 dstRow
+= dstRowStride
;
1091 * Store a 16-bit integer depth component texture image.
1094 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1096 const GLuint depthScale
= 0xffff;
1097 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1099 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1100 ASSERT(texelBytes
== sizeof(GLushort
));
1102 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1103 ctx
->Pixel
.DepthBias
== 0.0f
&&
1104 !srcPacking
->SwapBytes
&&
1105 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1106 srcFormat
== GL_DEPTH_COMPONENT
&&
1107 srcType
== GL_UNSIGNED_SHORT
) {
1108 /* simple memcpy path */
1109 memcpy_texture(ctx
, dims
,
1110 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1113 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1114 srcAddr
, srcPacking
);
1119 for (img
= 0; img
< srcDepth
; img
++) {
1120 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1121 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1122 + dstYoffset
* dstRowStride
1123 + dstXoffset
* texelBytes
;
1124 for (row
= 0; row
< srcHeight
; row
++) {
1125 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1126 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1127 GLushort
*dst16
= (GLushort
*) dstRow
;
1128 _mesa_unpack_depth_span(ctx
, srcWidth
,
1129 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1130 srcType
, src
, srcPacking
);
1131 dstRow
+= dstRowStride
;
1140 * Store an rgb565 or rgb565_rev texture image.
1143 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1145 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1146 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1148 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1149 dstFormat
== MESA_FORMAT_RGB565_REV
);
1150 ASSERT(texelBytes
== 2);
1152 if (!ctx
->_ImageTransferState
&&
1153 !srcPacking
->SwapBytes
&&
1154 dstFormat
== MESA_FORMAT_RGB565
&&
1155 baseInternalFormat
== GL_RGB
&&
1156 srcFormat
== GL_RGB
&&
1157 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1158 /* simple memcpy path */
1159 memcpy_texture(ctx
, dims
,
1160 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1163 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1164 srcAddr
, srcPacking
);
1166 else if (!ctx
->_ImageTransferState
&&
1167 !srcPacking
->SwapBytes
&&
1168 baseInternalFormat
== GL_RGB
&&
1169 srcFormat
== GL_RGB
&&
1170 srcType
== GL_UNSIGNED_BYTE
&&
1172 /* do optimized tex store */
1173 const GLint srcRowStride
=
1174 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1175 const GLubyte
*src
= (const GLubyte
*)
1176 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1177 srcFormat
, srcType
, 0, 0, 0);
1178 GLubyte
*dst
= (GLubyte
*) dstAddr
1179 + dstYoffset
* dstRowStride
1180 + dstXoffset
* texelBytes
;
1182 for (row
= 0; row
< srcHeight
; row
++) {
1183 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1184 GLushort
*dstUS
= (GLushort
*) dst
;
1185 /* check for byteswapped format */
1186 if (dstFormat
== MESA_FORMAT_RGB565
) {
1187 for (col
= 0; col
< srcWidth
; col
++) {
1188 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1193 for (col
= 0; col
< srcWidth
; col
++) {
1194 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1198 dst
+= dstRowStride
;
1199 src
+= srcRowStride
;
1204 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1207 srcWidth
, srcHeight
, srcDepth
,
1208 srcFormat
, srcType
, srcAddr
,
1210 const GLchan
*src
= tempImage
;
1211 GLint img
, row
, col
;
1214 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1215 for (img
= 0; img
< srcDepth
; img
++) {
1216 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1217 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1218 + dstYoffset
* dstRowStride
1219 + dstXoffset
* texelBytes
;
1220 for (row
= 0; row
< srcHeight
; row
++) {
1221 GLushort
*dstUS
= (GLushort
*) dstRow
;
1222 /* check for byteswapped format */
1223 if (dstFormat
== MESA_FORMAT_RGB565
) {
1224 for (col
= 0; col
< srcWidth
; col
++) {
1225 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1226 CHAN_TO_UBYTE(src
[GCOMP
]),
1227 CHAN_TO_UBYTE(src
[BCOMP
]) );
1232 for (col
= 0; col
< srcWidth
; col
++) {
1233 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1234 CHAN_TO_UBYTE(src
[GCOMP
]),
1235 CHAN_TO_UBYTE(src
[BCOMP
]) );
1239 dstRow
+= dstRowStride
;
1242 _mesa_free((void *) tempImage
);
1249 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1252 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1254 const GLboolean littleEndian
= _mesa_little_endian();
1255 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1256 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1258 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1259 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1260 ASSERT(texelBytes
== 4);
1262 if (!ctx
->_ImageTransferState
&&
1263 !srcPacking
->SwapBytes
&&
1264 dstFormat
== MESA_FORMAT_RGBA8888
&&
1265 baseInternalFormat
== GL_RGBA
&&
1266 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1267 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1268 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1269 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1270 /* simple memcpy path */
1271 memcpy_texture(ctx
, dims
,
1272 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1275 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1276 srcAddr
, srcPacking
);
1278 else if (!ctx
->_ImageTransferState
&&
1279 !srcPacking
->SwapBytes
&&
1280 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1281 baseInternalFormat
== GL_RGBA
&&
1282 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1283 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1284 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1285 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1286 /* simple memcpy path */
1287 memcpy_texture(ctx
, dims
,
1288 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1291 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1292 srcAddr
, srcPacking
);
1294 else if (!ctx
->_ImageTransferState
&&
1295 (srcType
== GL_UNSIGNED_BYTE
||
1296 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1297 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1298 can_swizzle(baseInternalFormat
) &&
1299 can_swizzle(srcFormat
)) {
1303 /* dstmap - how to swizzle from RGBA to dst format:
1305 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1306 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1319 _mesa_swizzle_ubyte_image(ctx
, dims
,
1324 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1325 dstRowStride
, dstImageOffsets
,
1326 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1331 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1334 srcWidth
, srcHeight
, srcDepth
,
1335 srcFormat
, srcType
, srcAddr
,
1337 const GLchan
*src
= tempImage
;
1338 GLint img
, row
, col
;
1341 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1342 for (img
= 0; img
< srcDepth
; img
++) {
1343 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1344 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1345 + dstYoffset
* dstRowStride
1346 + dstXoffset
* texelBytes
;
1347 for (row
= 0; row
< srcHeight
; row
++) {
1348 GLuint
*dstUI
= (GLuint
*) dstRow
;
1349 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1350 for (col
= 0; col
< srcWidth
; col
++) {
1351 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1352 CHAN_TO_UBYTE(src
[GCOMP
]),
1353 CHAN_TO_UBYTE(src
[BCOMP
]),
1354 CHAN_TO_UBYTE(src
[ACOMP
]) );
1359 for (col
= 0; col
< srcWidth
; col
++) {
1360 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1361 CHAN_TO_UBYTE(src
[GCOMP
]),
1362 CHAN_TO_UBYTE(src
[BCOMP
]),
1363 CHAN_TO_UBYTE(src
[ACOMP
]) );
1367 dstRow
+= dstRowStride
;
1370 _mesa_free((void *) tempImage
);
1377 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1379 const GLboolean littleEndian
= _mesa_little_endian();
1380 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1381 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1383 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1384 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1385 dstFormat
== MESA_FORMAT_XRGB8888
);
1386 ASSERT(texelBytes
== 4);
1388 if (!ctx
->_ImageTransferState
&&
1389 !srcPacking
->SwapBytes
&&
1390 (dstFormat
== MESA_FORMAT_ARGB8888
||
1391 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1392 baseInternalFormat
== GL_RGBA
&&
1393 srcFormat
== GL_BGRA
&&
1394 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1395 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1396 /* simple memcpy path (little endian) */
1397 memcpy_texture(ctx
, dims
,
1398 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1401 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1402 srcAddr
, srcPacking
);
1404 else if (!ctx
->_ImageTransferState
&&
1405 !srcPacking
->SwapBytes
&&
1406 dstFormat
== MESA_FORMAT_ARGB8888_REV
&&
1407 baseInternalFormat
== GL_RGBA
&&
1408 srcFormat
== GL_BGRA
&&
1409 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1410 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1411 /* simple memcpy path (big endian) */
1412 memcpy_texture(ctx
, dims
,
1413 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1416 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1417 srcAddr
, srcPacking
);
1419 else if (!ctx
->_ImageTransferState
&&
1420 !srcPacking
->SwapBytes
&&
1421 (dstFormat
== MESA_FORMAT_ARGB8888
||
1422 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1423 srcFormat
== GL_RGB
&&
1424 (baseInternalFormat
== GL_RGBA
||
1425 baseInternalFormat
== GL_RGB
) &&
1426 srcType
== GL_UNSIGNED_BYTE
) {
1428 for (img
= 0; img
< srcDepth
; img
++) {
1429 const GLint srcRowStride
=
1430 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1431 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1432 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1433 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1434 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1435 + dstYoffset
* dstRowStride
1436 + dstXoffset
* texelBytes
;
1437 for (row
= 0; row
< srcHeight
; row
++) {
1438 GLuint
*d4
= (GLuint
*) dstRow
;
1439 for (col
= 0; col
< srcWidth
; col
++) {
1440 d4
[col
] = PACK_COLOR_8888(0xff,
1441 srcRow
[col
* 3 + RCOMP
],
1442 srcRow
[col
* 3 + GCOMP
],
1443 srcRow
[col
* 3 + BCOMP
]);
1445 dstRow
+= dstRowStride
;
1446 srcRow
+= srcRowStride
;
1450 else if (!ctx
->_ImageTransferState
&&
1451 !srcPacking
->SwapBytes
&&
1452 dstFormat
== MESA_FORMAT_ARGB8888
&&
1453 srcFormat
== GL_RGBA
&&
1454 baseInternalFormat
== GL_RGBA
&&
1455 srcType
== GL_UNSIGNED_BYTE
) {
1456 /* same as above case, but src data has alpha too */
1457 GLint img
, row
, col
;
1458 /* For some reason, streaming copies to write-combined regions
1459 * are extremely sensitive to the characteristics of how the
1460 * source data is retrieved. By reordering the source reads to
1461 * be in-order, the speed of this operation increases by half.
1462 * Strangely the same isn't required for the RGB path, above.
1464 for (img
= 0; img
< srcDepth
; img
++) {
1465 const GLint srcRowStride
=
1466 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1467 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1468 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1469 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1470 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1471 + dstYoffset
* dstRowStride
1472 + dstXoffset
* texelBytes
;
1473 for (row
= 0; row
< srcHeight
; row
++) {
1474 GLuint
*d4
= (GLuint
*) dstRow
;
1475 for (col
= 0; col
< srcWidth
; col
++) {
1476 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1477 srcRow
[col
* 4 + RCOMP
],
1478 srcRow
[col
* 4 + GCOMP
],
1479 srcRow
[col
* 4 + BCOMP
]);
1481 dstRow
+= dstRowStride
;
1482 srcRow
+= srcRowStride
;
1486 else if (!ctx
->_ImageTransferState
&&
1487 (srcType
== GL_UNSIGNED_BYTE
||
1488 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1489 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1490 can_swizzle(baseInternalFormat
) &&
1491 can_swizzle(srcFormat
)) {
1495 /* dstmap - how to swizzle from RGBA to dst format:
1497 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1498 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1499 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
)) {
1500 dstmap
[3] = 3; /* alpha */
1501 dstmap
[2] = 0; /* red */
1502 dstmap
[1] = 1; /* green */
1503 dstmap
[0] = 2; /* blue */
1506 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1507 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1508 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1515 _mesa_swizzle_ubyte_image(ctx
, dims
,
1521 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1524 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1529 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1532 srcWidth
, srcHeight
, srcDepth
,
1533 srcFormat
, srcType
, srcAddr
,
1535 const GLchan
*src
= tempImage
;
1536 GLint img
, row
, col
;
1539 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1540 for (img
= 0; img
< srcDepth
; img
++) {
1541 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1542 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1543 + dstYoffset
* dstRowStride
1544 + dstXoffset
* texelBytes
;
1545 for (row
= 0; row
< srcHeight
; row
++) {
1546 GLuint
*dstUI
= (GLuint
*) dstRow
;
1547 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1548 for (col
= 0; col
< srcWidth
; col
++) {
1549 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1550 CHAN_TO_UBYTE(src
[RCOMP
]),
1551 CHAN_TO_UBYTE(src
[GCOMP
]),
1552 CHAN_TO_UBYTE(src
[BCOMP
]) );
1556 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1557 for (col
= 0; col
< srcWidth
; col
++) {
1558 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1559 CHAN_TO_UBYTE(src
[RCOMP
]),
1560 CHAN_TO_UBYTE(src
[GCOMP
]),
1561 CHAN_TO_UBYTE(src
[BCOMP
]) );
1566 for (col
= 0; col
< srcWidth
; col
++) {
1567 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1568 CHAN_TO_UBYTE(src
[RCOMP
]),
1569 CHAN_TO_UBYTE(src
[GCOMP
]),
1570 CHAN_TO_UBYTE(src
[BCOMP
]) );
1574 dstRow
+= dstRowStride
;
1577 _mesa_free((void *) tempImage
);
1584 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1586 const GLboolean littleEndian
= _mesa_little_endian();
1587 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1588 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1590 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1591 ASSERT(texelBytes
== 3);
1593 if (!ctx
->_ImageTransferState
&&
1594 !srcPacking
->SwapBytes
&&
1595 baseInternalFormat
== GL_RGB
&&
1596 srcFormat
== GL_BGR
&&
1597 srcType
== GL_UNSIGNED_BYTE
&&
1599 /* simple memcpy path */
1600 memcpy_texture(ctx
, dims
,
1601 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1604 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1605 srcAddr
, srcPacking
);
1607 else if (!ctx
->_ImageTransferState
&&
1608 !srcPacking
->SwapBytes
&&
1609 srcFormat
== GL_RGBA
&&
1610 srcType
== GL_UNSIGNED_BYTE
) {
1611 /* extract RGB from RGBA */
1612 GLint img
, row
, col
;
1613 for (img
= 0; img
< srcDepth
; img
++) {
1614 const GLint srcRowStride
=
1615 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1616 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1617 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1618 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1619 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1620 + dstYoffset
* dstRowStride
1621 + dstXoffset
* texelBytes
;
1622 for (row
= 0; row
< srcHeight
; row
++) {
1623 for (col
= 0; col
< srcWidth
; col
++) {
1624 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1625 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1626 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1628 dstRow
+= dstRowStride
;
1629 srcRow
+= srcRowStride
;
1633 else if (!ctx
->_ImageTransferState
&&
1634 srcType
== GL_UNSIGNED_BYTE
&&
1635 can_swizzle(baseInternalFormat
) &&
1636 can_swizzle(srcFormat
)) {
1640 /* dstmap - how to swizzle from RGBA to dst format:
1645 dstmap
[3] = ONE
; /* ? */
1647 _mesa_swizzle_ubyte_image(ctx
, dims
,
1652 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1653 dstRowStride
, dstImageOffsets
,
1654 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1659 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1662 srcWidth
, srcHeight
, srcDepth
,
1663 srcFormat
, srcType
, srcAddr
,
1665 const GLchan
*src
= (const GLchan
*) tempImage
;
1666 GLint img
, row
, col
;
1669 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1670 for (img
= 0; img
< srcDepth
; img
++) {
1671 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1672 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1673 + dstYoffset
* dstRowStride
1674 + dstXoffset
* texelBytes
;
1675 for (row
= 0; row
< srcHeight
; row
++) {
1678 for (col
= 0; col
< srcWidth
; col
++) {
1679 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1680 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1681 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1686 for (col
= 0; col
< srcWidth
; col
++) {
1687 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1688 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1689 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1694 for (col
= 0; col
< srcWidth
; col
++) {
1695 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1696 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1697 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1701 dstRow
+= dstRowStride
;
1704 _mesa_free((void *) tempImage
);
1711 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1713 const GLboolean littleEndian
= _mesa_little_endian();
1714 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1715 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1717 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1718 ASSERT(texelBytes
== 3);
1720 if (!ctx
->_ImageTransferState
&&
1721 !srcPacking
->SwapBytes
&&
1722 baseInternalFormat
== GL_RGB
&&
1723 srcFormat
== GL_RGB
&&
1724 srcType
== GL_UNSIGNED_BYTE
&&
1726 /* simple memcpy path */
1727 memcpy_texture(ctx
, dims
,
1728 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1731 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1732 srcAddr
, srcPacking
);
1734 else if (!ctx
->_ImageTransferState
&&
1735 !srcPacking
->SwapBytes
&&
1736 srcFormat
== GL_RGBA
&&
1737 srcType
== GL_UNSIGNED_BYTE
) {
1738 /* extract BGR from RGBA */
1740 for (img
= 0; img
< srcDepth
; img
++) {
1741 const GLint srcRowStride
=
1742 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1743 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1744 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1745 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1746 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1747 + dstYoffset
* dstRowStride
1748 + dstXoffset
* texelBytes
;
1749 for (row
= 0; row
< srcHeight
; row
++) {
1750 for (col
= 0; col
< srcWidth
; col
++) {
1751 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1752 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1753 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1755 dstRow
+= dstRowStride
;
1756 srcRow
+= srcRowStride
;
1760 else if (!ctx
->_ImageTransferState
&&
1761 srcType
== GL_UNSIGNED_BYTE
&&
1762 can_swizzle(baseInternalFormat
) &&
1763 can_swizzle(srcFormat
)) {
1767 /* dstmap - how to swizzle from RGBA to dst format:
1772 dstmap
[3] = ONE
; /* ? */
1774 _mesa_swizzle_ubyte_image(ctx
, dims
,
1779 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1780 dstRowStride
, dstImageOffsets
,
1781 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1786 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1789 srcWidth
, srcHeight
, srcDepth
,
1790 srcFormat
, srcType
, srcAddr
,
1792 const GLchan
*src
= (const GLchan
*) tempImage
;
1793 GLint img
, row
, col
;
1796 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1797 for (img
= 0; img
< srcDepth
; img
++) {
1798 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1799 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1800 + dstYoffset
* dstRowStride
1801 + dstXoffset
* texelBytes
;
1802 for (row
= 0; row
< srcHeight
; row
++) {
1803 for (col
= 0; col
< srcWidth
; col
++) {
1804 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1805 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1806 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1809 dstRow
+= dstRowStride
;
1812 _mesa_free((void *) tempImage
);
1819 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1821 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1822 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1824 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1825 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1826 ASSERT(texelBytes
== 2);
1828 if (!ctx
->_ImageTransferState
&&
1829 !srcPacking
->SwapBytes
&&
1830 dstFormat
== MESA_FORMAT_ARGB4444
&&
1831 baseInternalFormat
== GL_RGBA
&&
1832 srcFormat
== GL_BGRA
&&
1833 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1834 /* simple memcpy path */
1835 memcpy_texture(ctx
, dims
,
1836 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1839 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1840 srcAddr
, srcPacking
);
1844 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1847 srcWidth
, srcHeight
, srcDepth
,
1848 srcFormat
, srcType
, srcAddr
,
1850 const GLchan
*src
= tempImage
;
1851 GLint img
, row
, col
;
1854 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1855 for (img
= 0; img
< srcDepth
; img
++) {
1856 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1857 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1858 + dstYoffset
* dstRowStride
1859 + dstXoffset
* texelBytes
;
1860 for (row
= 0; row
< srcHeight
; row
++) {
1861 GLushort
*dstUS
= (GLushort
*) dstRow
;
1862 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1863 for (col
= 0; col
< srcWidth
; col
++) {
1864 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1865 CHAN_TO_UBYTE(src
[RCOMP
]),
1866 CHAN_TO_UBYTE(src
[GCOMP
]),
1867 CHAN_TO_UBYTE(src
[BCOMP
]) );
1872 for (col
= 0; col
< srcWidth
; col
++) {
1873 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1874 CHAN_TO_UBYTE(src
[RCOMP
]),
1875 CHAN_TO_UBYTE(src
[GCOMP
]),
1876 CHAN_TO_UBYTE(src
[BCOMP
]) );
1880 dstRow
+= dstRowStride
;
1883 _mesa_free((void *) tempImage
);
1889 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1891 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1892 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1894 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1895 ASSERT(texelBytes
== 2);
1897 if (!ctx
->_ImageTransferState
&&
1898 !srcPacking
->SwapBytes
&&
1899 dstFormat
== MESA_FORMAT_RGBA5551
&&
1900 baseInternalFormat
== GL_RGBA
&&
1901 srcFormat
== GL_RGBA
&&
1902 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1903 /* simple memcpy path */
1904 memcpy_texture(ctx
, dims
,
1905 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1908 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1909 srcAddr
, srcPacking
);
1913 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1916 srcWidth
, srcHeight
, srcDepth
,
1917 srcFormat
, srcType
, srcAddr
,
1919 const GLchan
*src
=tempImage
;
1920 GLint img
, row
, col
;
1923 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1924 for (img
= 0; img
< srcDepth
; img
++) {
1925 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1926 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1927 + dstYoffset
* dstRowStride
1928 + dstXoffset
* texelBytes
;
1929 for (row
= 0; row
< srcHeight
; row
++) {
1930 GLushort
*dstUS
= (GLushort
*) dstRow
;
1931 for (col
= 0; col
< srcWidth
; col
++) {
1932 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1933 CHAN_TO_UBYTE(src
[GCOMP
]),
1934 CHAN_TO_UBYTE(src
[BCOMP
]),
1935 CHAN_TO_UBYTE(src
[ACOMP
]) );
1938 dstRow
+= dstRowStride
;
1941 _mesa_free((void *) tempImage
);
1947 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1949 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1950 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1952 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1953 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1954 ASSERT(texelBytes
== 2);
1956 if (!ctx
->_ImageTransferState
&&
1957 !srcPacking
->SwapBytes
&&
1958 dstFormat
== MESA_FORMAT_ARGB1555
&&
1959 baseInternalFormat
== GL_RGBA
&&
1960 srcFormat
== GL_BGRA
&&
1961 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1962 /* simple memcpy path */
1963 memcpy_texture(ctx
, dims
,
1964 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1967 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1968 srcAddr
, srcPacking
);
1972 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1975 srcWidth
, srcHeight
, srcDepth
,
1976 srcFormat
, srcType
, srcAddr
,
1978 const GLchan
*src
=tempImage
;
1979 GLint img
, row
, col
;
1982 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1983 for (img
= 0; img
< srcDepth
; img
++) {
1984 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1985 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1986 + dstYoffset
* dstRowStride
1987 + dstXoffset
* texelBytes
;
1988 for (row
= 0; row
< srcHeight
; row
++) {
1989 GLushort
*dstUS
= (GLushort
*) dstRow
;
1990 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1991 for (col
= 0; col
< srcWidth
; col
++) {
1992 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
1993 CHAN_TO_UBYTE(src
[RCOMP
]),
1994 CHAN_TO_UBYTE(src
[GCOMP
]),
1995 CHAN_TO_UBYTE(src
[BCOMP
]) );
2000 for (col
= 0; col
< srcWidth
; col
++) {
2001 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2002 CHAN_TO_UBYTE(src
[RCOMP
]),
2003 CHAN_TO_UBYTE(src
[GCOMP
]),
2004 CHAN_TO_UBYTE(src
[BCOMP
]) );
2008 dstRow
+= dstRowStride
;
2011 _mesa_free((void *) tempImage
);
2018 _mesa_texstore_al88(TEXSTORE_PARAMS
)
2020 const GLboolean littleEndian
= _mesa_little_endian();
2021 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2022 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2024 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2025 dstFormat
== MESA_FORMAT_AL88_REV
);
2026 ASSERT(texelBytes
== 2);
2028 if (!ctx
->_ImageTransferState
&&
2029 !srcPacking
->SwapBytes
&&
2030 dstFormat
== MESA_FORMAT_AL88
&&
2031 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2032 srcFormat
== GL_LUMINANCE_ALPHA
&&
2033 srcType
== GL_UNSIGNED_BYTE
&&
2035 /* simple memcpy path */
2036 memcpy_texture(ctx
, dims
,
2037 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2040 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2041 srcAddr
, srcPacking
);
2043 else if (!ctx
->_ImageTransferState
&&
2045 srcType
== GL_UNSIGNED_BYTE
&&
2046 can_swizzle(baseInternalFormat
) &&
2047 can_swizzle(srcFormat
)) {
2051 /* dstmap - how to swizzle from RGBA to dst format:
2053 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2054 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2062 dstmap
[2] = ZERO
; /* ? */
2063 dstmap
[3] = ONE
; /* ? */
2065 _mesa_swizzle_ubyte_image(ctx
, dims
,
2070 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2071 dstRowStride
, dstImageOffsets
,
2072 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2077 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2080 srcWidth
, srcHeight
, srcDepth
,
2081 srcFormat
, srcType
, srcAddr
,
2083 const GLchan
*src
= tempImage
;
2084 GLint img
, row
, col
;
2087 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2088 for (img
= 0; img
< srcDepth
; img
++) {
2089 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2090 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2091 + dstYoffset
* dstRowStride
2092 + dstXoffset
* texelBytes
;
2093 for (row
= 0; row
< srcHeight
; row
++) {
2094 GLushort
*dstUS
= (GLushort
*) dstRow
;
2095 if (dstFormat
== MESA_FORMAT_AL88
) {
2096 for (col
= 0; col
< srcWidth
; col
++) {
2097 /* src[0] is luminance, src[1] is alpha */
2098 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2099 CHAN_TO_UBYTE(src
[0]) );
2104 for (col
= 0; col
< srcWidth
; col
++) {
2105 /* src[0] is luminance, src[1] is alpha */
2106 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2107 CHAN_TO_UBYTE(src
[0]) );
2111 dstRow
+= dstRowStride
;
2114 _mesa_free((void *) tempImage
);
2121 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2123 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2124 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2126 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2127 ASSERT(texelBytes
== 1);
2129 if (!ctx
->_ImageTransferState
&&
2130 !srcPacking
->SwapBytes
&&
2131 baseInternalFormat
== GL_RGB
&&
2132 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2133 /* simple memcpy path */
2134 memcpy_texture(ctx
, dims
,
2135 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2138 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2139 srcAddr
, srcPacking
);
2143 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2146 srcWidth
, srcHeight
, srcDepth
,
2147 srcFormat
, srcType
, srcAddr
,
2149 const GLchan
*src
= tempImage
;
2150 GLint img
, row
, col
;
2153 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2154 for (img
= 0; img
< srcDepth
; img
++) {
2155 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2156 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2157 + dstYoffset
* dstRowStride
2158 + dstXoffset
* texelBytes
;
2159 for (row
= 0; row
< srcHeight
; row
++) {
2160 for (col
= 0; col
< srcWidth
; col
++) {
2161 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2162 CHAN_TO_UBYTE(src
[GCOMP
]),
2163 CHAN_TO_UBYTE(src
[BCOMP
]) );
2166 dstRow
+= dstRowStride
;
2169 _mesa_free((void *) tempImage
);
2176 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2179 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2181 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2182 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2184 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2185 dstFormat
== MESA_FORMAT_L8
||
2186 dstFormat
== MESA_FORMAT_I8
);
2187 ASSERT(texelBytes
== 1);
2189 if (!ctx
->_ImageTransferState
&&
2190 !srcPacking
->SwapBytes
&&
2191 baseInternalFormat
== srcFormat
&&
2192 srcType
== GL_UNSIGNED_BYTE
) {
2193 /* simple memcpy path */
2194 memcpy_texture(ctx
, dims
,
2195 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2198 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2199 srcAddr
, srcPacking
);
2201 else if (!ctx
->_ImageTransferState
&&
2202 srcType
== GL_UNSIGNED_BYTE
&&
2203 can_swizzle(baseInternalFormat
) &&
2204 can_swizzle(srcFormat
)) {
2208 /* dstmap - how to swizzle from RGBA to dst format:
2210 if (dstFormat
== MESA_FORMAT_A8
) {
2216 dstmap
[1] = ZERO
; /* ? */
2217 dstmap
[2] = ZERO
; /* ? */
2218 dstmap
[3] = ONE
; /* ? */
2220 _mesa_swizzle_ubyte_image(ctx
, dims
,
2225 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2226 dstRowStride
, dstImageOffsets
,
2227 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2232 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2235 srcWidth
, srcHeight
, srcDepth
,
2236 srcFormat
, srcType
, srcAddr
,
2238 const GLchan
*src
= tempImage
;
2239 GLint img
, row
, col
;
2242 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2243 for (img
= 0; img
< srcDepth
; img
++) {
2244 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2245 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2246 + dstYoffset
* dstRowStride
2247 + dstXoffset
* texelBytes
;
2248 for (row
= 0; row
< srcHeight
; row
++) {
2249 for (col
= 0; col
< srcWidth
; col
++) {
2250 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2252 dstRow
+= dstRowStride
;
2256 _mesa_free((void *) tempImage
);
2264 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2266 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2268 (void) dims
; (void) baseInternalFormat
;
2269 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2270 ASSERT(texelBytes
== 1);
2271 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2273 if (!ctx
->_ImageTransferState
&&
2274 !srcPacking
->SwapBytes
&&
2275 srcFormat
== GL_COLOR_INDEX
&&
2276 srcType
== GL_UNSIGNED_BYTE
) {
2277 /* simple memcpy path */
2278 memcpy_texture(ctx
, dims
,
2279 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2282 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2283 srcAddr
, srcPacking
);
2288 for (img
= 0; img
< srcDepth
; img
++) {
2289 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2290 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2291 + dstYoffset
* dstRowStride
2292 + dstXoffset
* texelBytes
;
2293 for (row
= 0; row
< srcHeight
; row
++) {
2294 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2295 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2296 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2297 srcType
, src
, srcPacking
,
2298 ctx
->_ImageTransferState
);
2299 dstRow
+= dstRowStride
;
2308 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2311 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2313 const GLboolean littleEndian
= _mesa_little_endian();
2314 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2316 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2318 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2319 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2320 ASSERT(texelBytes
== 2);
2321 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2322 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2323 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2324 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2325 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2327 /* always just memcpy since no pixel transfer ops apply */
2328 memcpy_texture(ctx
, dims
,
2329 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2332 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2333 srcAddr
, srcPacking
);
2335 /* Check if we need byte swapping */
2336 /* XXX the logic here _might_ be wrong */
2337 if (srcPacking
->SwapBytes
^
2338 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2339 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2342 for (img
= 0; img
< srcDepth
; img
++) {
2343 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2344 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2345 + dstYoffset
* dstRowStride
2346 + dstXoffset
* texelBytes
;
2347 for (row
= 0; row
< srcHeight
; row
++) {
2348 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2349 dstRow
+= dstRowStride
;
2357 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2359 const GLboolean littleEndian
= _mesa_little_endian();
2360 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2362 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2363 ASSERT(texelBytes
== 2);
2364 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2365 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2366 (srcFormat
== GL_DUDV_ATI
));
2367 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2369 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2371 /* simple memcpy path */
2372 memcpy_texture(ctx
, dims
,
2373 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2376 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2377 srcAddr
, srcPacking
);
2379 else if (srcType
== GL_BYTE
) {
2383 /* dstmap - how to swizzle from RGBA to dst format:
2393 dstmap
[2] = ZERO
; /* ? */
2394 dstmap
[3] = ONE
; /* ? */
2396 _mesa_swizzle_ubyte_image(ctx
, dims
,
2397 GL_LUMINANCE_ALPHA
, /* hack */
2398 GL_UNSIGNED_BYTE
, /* hack */
2399 GL_LUMINANCE_ALPHA
, /* hack */
2401 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2402 dstRowStride
, dstImageOffsets
,
2403 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2407 /* general path - note this is defined for 2d textures only */
2408 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2409 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2410 srcFormat
, srcType
);
2411 GLbyte
*tempImage
, *dst
, *src
;
2414 tempImage
= (GLbyte
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
2415 * components
* sizeof(GLbyte
));
2419 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2420 srcWidth
, srcHeight
,
2425 for (row
= 0; row
< srcHeight
; row
++) {
2426 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2427 dst
, srcFormat
, srcType
, src
,
2429 dst
+= srcWidth
* components
;
2434 dst
= (GLbyte
*) dstAddr
2435 + dstYoffset
* dstRowStride
2436 + dstXoffset
* texelBytes
;
2437 for (row
= 0; row
< srcHeight
; row
++) {
2438 memcpy(dst
, src
, srcWidth
* texelBytes
);
2439 dst
+= dstRowStride
;
2440 src
+= srcWidth
* texelBytes
;
2442 _mesa_free((void *) tempImage
);
2448 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV
2451 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2453 const GLboolean littleEndian
= _mesa_little_endian();
2454 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2455 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2457 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2458 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2459 ASSERT(texelBytes
== 4);
2461 if (!ctx
->_ImageTransferState
&&
2462 !srcPacking
->SwapBytes
&&
2463 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2464 baseInternalFormat
== GL_RGBA
&&
2465 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2466 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2467 /* simple memcpy path */
2468 memcpy_texture(ctx
, dims
,
2469 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2472 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2473 srcAddr
, srcPacking
);
2475 else if (!ctx
->_ImageTransferState
&&
2476 !srcPacking
->SwapBytes
&&
2477 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2478 baseInternalFormat
== GL_RGBA
&&
2479 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2480 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2481 /* simple memcpy path */
2482 memcpy_texture(ctx
, dims
,
2483 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2486 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2487 srcAddr
, srcPacking
);
2489 else if (!ctx
->_ImageTransferState
&&
2490 (srcType
== GL_BYTE
) &&
2491 can_swizzle(baseInternalFormat
) &&
2492 can_swizzle(srcFormat
)) {
2496 /* dstmap - how to swizzle from RGBA to dst format:
2498 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2499 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2512 _mesa_swizzle_ubyte_image(ctx
, dims
,
2517 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2518 dstRowStride
, dstImageOffsets
,
2519 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2524 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2527 srcWidth
, srcHeight
, srcDepth
,
2528 srcFormat
, srcType
, srcAddr
,
2530 const GLfloat
*srcRow
= tempImage
;
2531 GLint img
, row
, col
;
2534 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2535 for (img
= 0; img
< srcDepth
; img
++) {
2536 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2537 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2538 + dstYoffset
* dstRowStride
2539 + dstXoffset
* texelBytes
;
2540 for (row
= 0; row
< srcHeight
; row
++) {
2541 GLuint
*dstUI
= (GLuint
*) dstRow
;
2542 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2543 for (col
= 0; col
< srcWidth
; col
++) {
2544 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2545 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2546 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2547 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2552 for (col
= 0; col
< srcWidth
; col
++) {
2553 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2554 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2555 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2556 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2560 dstRow
+= dstRowStride
;
2563 _mesa_free((void *) tempImage
);
2569 * Store a combined depth/stencil texture image.
2572 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2574 const GLfloat depthScale
= (GLfloat
) 0xffffff;
2575 const GLint srcRowStride
2576 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2580 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2581 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2582 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2584 /* In case we only upload depth we need to preserve the stencil */
2585 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2586 for (img
= 0; img
< srcDepth
; img
++) {
2587 GLuint
*dstRow
= (GLuint
*) dstAddr
2588 + dstImageOffsets
[dstZoffset
+ img
]
2589 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2592 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2593 srcWidth
, srcHeight
,
2596 for (row
= 0; row
< srcHeight
; row
++) {
2597 GLuint depth
[MAX_WIDTH
];
2599 _mesa_unpack_depth_span(ctx
, srcWidth
,
2600 GL_UNSIGNED_INT
, /* dst type */
2601 depth
, /* dst addr */
2603 srcType
, src
, srcPacking
);
2605 for (i
= 0; i
< srcWidth
; i
++)
2606 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2608 src
+= srcRowStride
;
2609 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2613 else if (ctx
->Pixel
.DepthScale
== 1.0f
&&
2614 ctx
->Pixel
.DepthBias
== 0.0f
&&
2615 !srcPacking
->SwapBytes
) {
2617 memcpy_texture(ctx
, dims
,
2618 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2621 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2622 srcAddr
, srcPacking
);
2626 const GLint srcRowStride
2627 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2631 for (img
= 0; img
< srcDepth
; img
++) {
2632 GLuint
*dstRow
= (GLuint
*) dstAddr
2633 + dstImageOffsets
[dstZoffset
+ img
]
2634 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2637 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2638 srcWidth
, srcHeight
,
2641 for (row
= 0; row
< srcHeight
; row
++) {
2642 GLubyte stencil
[MAX_WIDTH
];
2644 /* the 24 depth bits will be in the high position: */
2645 _mesa_unpack_depth_span(ctx
, srcWidth
,
2646 GL_UNSIGNED_INT_24_8_EXT
, /* dst type */
2647 dstRow
, /* dst addr */
2648 (GLuint
) depthScale
,
2649 srcType
, src
, srcPacking
);
2650 /* get the 8-bit stencil values */
2651 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2652 GL_UNSIGNED_BYTE
, /* dst type */
2653 stencil
, /* dst addr */
2654 srcType
, src
, srcPacking
,
2655 ctx
->_ImageTransferState
);
2656 /* merge stencil values into depth values */
2657 for (i
= 0; i
< srcWidth
; i
++)
2658 dstRow
[i
] |= stencil
[i
];
2660 src
+= srcRowStride
;
2661 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2670 * Store a combined depth/stencil texture image.
2673 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2675 const GLuint depthScale
= 0xffffff;
2676 const GLint srcRowStride
2677 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2681 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2682 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2683 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2685 /* In case we only upload depth we need to preserve the stencil */
2686 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2687 for (img
= 0; img
< srcDepth
; img
++) {
2688 GLuint
*dstRow
= (GLuint
*) dstAddr
2689 + dstImageOffsets
[dstZoffset
+ img
]
2690 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2693 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2694 srcWidth
, srcHeight
,
2697 for (row
= 0; row
< srcHeight
; row
++) {
2698 GLuint depth
[MAX_WIDTH
];
2700 _mesa_unpack_depth_span(ctx
, srcWidth
,
2701 GL_UNSIGNED_INT
, /* dst type */
2702 depth
, /* dst addr */
2704 srcType
, src
, srcPacking
);
2706 for (i
= 0; i
< srcWidth
; i
++)
2707 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2709 src
+= srcRowStride
;
2710 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2715 for (img
= 0; img
< srcDepth
; img
++) {
2716 GLuint
*dstRow
= (GLuint
*) dstAddr
2717 + dstImageOffsets
[dstZoffset
+ img
]
2718 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2721 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2722 srcWidth
, srcHeight
,
2725 for (row
= 0; row
< srcHeight
; row
++) {
2726 GLubyte stencil
[MAX_WIDTH
];
2728 /* the 24 depth bits will be in the low position: */
2729 _mesa_unpack_depth_span(ctx
, srcWidth
,
2730 GL_UNSIGNED_INT
, /* dst type */
2731 dstRow
, /* dst addr */
2733 srcType
, src
, srcPacking
);
2734 /* get the 8-bit stencil values */
2735 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2736 GL_UNSIGNED_BYTE
, /* dst type */
2737 stencil
, /* dst addr */
2738 srcType
, src
, srcPacking
,
2739 ctx
->_ImageTransferState
);
2740 /* merge stencil values into depth values */
2741 for (i
= 0; i
< srcWidth
; i
++)
2742 dstRow
[i
] |= stencil
[i
] << 24;
2744 src
+= srcRowStride
;
2745 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2753 * Store an image in any of the formats:
2754 * _mesa_texformat_rgba_float32
2755 * _mesa_texformat_rgb_float32
2756 * _mesa_texformat_alpha_float32
2757 * _mesa_texformat_luminance_float32
2758 * _mesa_texformat_luminance_alpha_float32
2759 * _mesa_texformat_intensity_float32
2762 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2764 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2765 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2766 const GLint components
= _mesa_components_in_format(baseFormat
);
2768 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2769 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2770 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
2771 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
2772 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
2773 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
2774 ASSERT(baseInternalFormat
== GL_RGBA
||
2775 baseInternalFormat
== GL_RGB
||
2776 baseInternalFormat
== GL_ALPHA
||
2777 baseInternalFormat
== GL_LUMINANCE
||
2778 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2779 baseInternalFormat
== GL_INTENSITY
);
2780 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
2782 if (!ctx
->_ImageTransferState
&&
2783 !srcPacking
->SwapBytes
&&
2784 baseInternalFormat
== srcFormat
&&
2785 srcType
== GL_FLOAT
) {
2786 /* simple memcpy path */
2787 memcpy_texture(ctx
, dims
,
2788 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2791 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2792 srcAddr
, srcPacking
);
2796 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2799 srcWidth
, srcHeight
, srcDepth
,
2800 srcFormat
, srcType
, srcAddr
,
2802 const GLfloat
*srcRow
= tempImage
;
2807 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2808 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2809 for (img
= 0; img
< srcDepth
; img
++) {
2810 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2811 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2812 + dstYoffset
* dstRowStride
2813 + dstXoffset
* texelBytes
;
2814 for (row
= 0; row
< srcHeight
; row
++) {
2815 _mesa_memcpy(dstRow
, srcRow
, bytesPerRow
);
2816 dstRow
+= dstRowStride
;
2817 srcRow
+= srcWidth
* components
;
2821 _mesa_free((void *) tempImage
);
2828 * As above, but store 16-bit floats.
2831 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2833 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2834 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2835 const GLint components
= _mesa_components_in_format(baseFormat
);
2837 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2838 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2839 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
2840 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
2841 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
2842 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
2843 ASSERT(baseInternalFormat
== GL_RGBA
||
2844 baseInternalFormat
== GL_RGB
||
2845 baseInternalFormat
== GL_ALPHA
||
2846 baseInternalFormat
== GL_LUMINANCE
||
2847 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2848 baseInternalFormat
== GL_INTENSITY
);
2849 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
2851 if (!ctx
->_ImageTransferState
&&
2852 !srcPacking
->SwapBytes
&&
2853 baseInternalFormat
== srcFormat
&&
2854 srcType
== GL_HALF_FLOAT_ARB
) {
2855 /* simple memcpy path */
2856 memcpy_texture(ctx
, dims
,
2857 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2860 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2861 srcAddr
, srcPacking
);
2865 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2868 srcWidth
, srcHeight
, srcDepth
,
2869 srcFormat
, srcType
, srcAddr
,
2871 const GLfloat
*src
= tempImage
;
2875 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2876 for (img
= 0; img
< srcDepth
; img
++) {
2877 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2878 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2879 + dstYoffset
* dstRowStride
2880 + dstXoffset
* texelBytes
;
2881 for (row
= 0; row
< srcHeight
; row
++) {
2882 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2884 for (i
= 0; i
< srcWidth
* components
; i
++) {
2885 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2887 dstRow
+= dstRowStride
;
2888 src
+= srcWidth
* components
;
2892 _mesa_free((void *) tempImage
);
2898 #if FEATURE_EXT_texture_sRGB
2900 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
2902 gl_format newDstFormat
;
2905 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
2907 /* reuse normal rgb texstore code */
2908 newDstFormat
= MESA_FORMAT_RGB888
;
2910 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
2911 newDstFormat
, dstAddr
,
2912 dstXoffset
, dstYoffset
, dstZoffset
,
2913 dstRowStride
, dstImageOffsets
,
2914 srcWidth
, srcHeight
, srcDepth
,
2916 srcAddr
, srcPacking
);
2922 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
2924 gl_format newDstFormat
;
2927 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
2929 /* reuse normal rgba texstore code */
2930 newDstFormat
= MESA_FORMAT_RGBA8888
;
2931 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
2932 newDstFormat
, dstAddr
,
2933 dstXoffset
, dstYoffset
, dstZoffset
,
2934 dstRowStride
, dstImageOffsets
,
2935 srcWidth
, srcHeight
, srcDepth
,
2937 srcAddr
, srcPacking
);
2943 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
2945 gl_format newDstFormat
;
2948 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
2950 /* reuse normal rgba texstore code */
2951 newDstFormat
= MESA_FORMAT_ARGB8888
;
2953 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
2954 newDstFormat
, dstAddr
,
2955 dstXoffset
, dstYoffset
, dstZoffset
,
2956 dstRowStride
, dstImageOffsets
,
2957 srcWidth
, srcHeight
, srcDepth
,
2959 srcAddr
, srcPacking
);
2965 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
2967 gl_format newDstFormat
;
2970 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
2972 newDstFormat
= MESA_FORMAT_L8
;
2974 /* _mesa_textore_a8 handles luminance8 too */
2975 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
2976 newDstFormat
, dstAddr
,
2977 dstXoffset
, dstYoffset
, dstZoffset
,
2978 dstRowStride
, dstImageOffsets
,
2979 srcWidth
, srcHeight
, srcDepth
,
2981 srcAddr
, srcPacking
);
2987 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
2989 gl_format newDstFormat
;
2992 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
2994 /* reuse normal luminance/alpha texstore code */
2995 newDstFormat
= MESA_FORMAT_AL88
;
2997 k
= _mesa_texstore_al88(ctx
, dims
, baseInternalFormat
,
2998 newDstFormat
, dstAddr
,
2999 dstXoffset
, dstYoffset
, dstZoffset
,
3000 dstRowStride
, dstImageOffsets
,
3001 srcWidth
, srcHeight
, srcDepth
,
3003 srcAddr
, srcPacking
);
3007 #endif /* FEATURE_EXT_texture_sRGB */
3013 * Table mapping MESA_FORMAT_8 to _mesa_texstore_*()
3014 * XXX this is somewhat temporary.
3018 StoreTexImageFunc Store
;
3020 texstore_funcs
[MESA_FORMAT_COUNT
] =
3022 { MESA_FORMAT_NONE
, NULL
},
3023 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
3024 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
3025 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
3026 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
3027 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
3028 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
3029 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
3030 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
3031 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
3032 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
3033 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
3034 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
3035 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
3036 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
3037 { MESA_FORMAT_AL88
, _mesa_texstore_al88
},
3038 { MESA_FORMAT_AL88_REV
, _mesa_texstore_al88
},
3039 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
3040 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
3041 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
3042 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
3043 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
3044 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
3045 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
3046 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
3047 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
3048 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3049 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
3050 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3051 { MESA_FORMAT_S8
, NULL
/*_mesa_texstore_s8*/ },
3052 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3053 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3054 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3055 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3056 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3057 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3058 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3059 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3060 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3061 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3062 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3063 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3064 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3065 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3066 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3067 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3068 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3069 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3070 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3071 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3072 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3073 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3074 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3075 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3076 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3077 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3078 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3079 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3080 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3081 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3082 { MESA_FORMAT_SIGNED_RGBA_16
, NULL
},
3087 _mesa_texstore_null(TEXSTORE_PARAMS
)
3089 (void) ctx
; (void) dims
;
3090 (void) baseInternalFormat
;
3093 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
3094 (void) dstRowStride
; (void) dstImageOffsets
;
3095 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3096 (void) srcFormat
; (void) srcType
;
3100 /* should never happen */
3101 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3107 * Return the StoreTexImageFunc pointer to store an image in the given format.
3109 static StoreTexImageFunc
3110 _mesa_get_texstore_func(gl_format format
)
3114 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
3115 ASSERT(texstore_funcs
[i
].Name
== i
);
3118 ASSERT(texstore_funcs
[format
].Name
== format
);
3120 if (texstore_funcs
[format
].Store
)
3121 return texstore_funcs
[format
].Store
;
3123 return _mesa_texstore_null
;
3128 * Store user data into texture memory.
3129 * Called via glTex[Sub]Image1/2/3D()
3132 _mesa_texstore(TEXSTORE_PARAMS
)
3134 StoreTexImageFunc storeImage
;
3137 storeImage
= _mesa_get_texstore_func(dstFormat
);
3139 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3140 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3141 dstRowStride
, dstImageOffsets
,
3142 srcWidth
, srcHeight
, srcDepth
,
3143 srcFormat
, srcType
, srcAddr
, srcPacking
);
3149 * Check if an unpack PBO is active prior to fetching a texture image.
3150 * If so, do bounds checking and map the buffer into main memory.
3151 * Any errors detected will be recorded.
3152 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3155 _mesa_validate_pbo_teximage(GLcontext
*ctx
, GLuint dimensions
,
3156 GLsizei width
, GLsizei height
, GLsizei depth
,
3157 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3158 const struct gl_pixelstore_attrib
*unpack
,
3159 const char *funcName
)
3163 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
3167 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
3168 format
, type
, pixels
)) {
3169 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3173 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3174 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
3176 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3180 return ADD_POINTERS(buf
, pixels
);
3185 * Check if an unpack PBO is active prior to fetching a compressed texture
3187 * If so, do bounds checking and map the buffer into main memory.
3188 * Any errors detected will be recorded.
3189 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3192 _mesa_validate_pbo_compressed_teximage(GLcontext
*ctx
,
3193 GLsizei imageSize
, const GLvoid
*pixels
,
3194 const struct gl_pixelstore_attrib
*packing
,
3195 const char *funcName
)
3199 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
3200 /* not using a PBO - return pointer unchanged */
3203 if ((const GLubyte
*) pixels
+ imageSize
>
3204 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
3205 /* out of bounds read! */
3206 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3210 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3211 GL_READ_ONLY_ARB
, packing
->BufferObj
);
3213 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3217 return ADD_POINTERS(buf
, pixels
);
3222 * This function must be called after either of the validate_pbo_*_teximage()
3223 * functions. It unmaps the PBO buffer if it was mapped earlier.
3226 _mesa_unmap_teximage_pbo(GLcontext
*ctx
,
3227 const struct gl_pixelstore_attrib
*unpack
)
3229 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
3230 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3236 /** Return texture size in bytes */
3238 texture_size(const struct gl_texture_image
*texImage
)
3240 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
3241 texImage
->Height
, texImage
->Depth
);
3246 /** Return row stride in bytes */
3248 texture_row_stride(const struct gl_texture_image
*texImage
)
3250 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
3258 * This is the software fallback for Driver.TexImage1D()
3259 * and Driver.CopyTexImage1D().
3260 * \sa _mesa_store_teximage2d()
3261 * Note that the width may not be the actual texture width since it may
3262 * be changed by convolution w/ GL_REDUCE. The texImage->Width field will
3263 * have the actual texture size.
3266 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3267 GLint internalFormat
,
3268 GLint width
, GLint border
,
3269 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3270 const struct gl_pixelstore_attrib
*packing
,
3271 struct gl_texture_object
*texObj
,
3272 struct gl_texture_image
*texImage
)
3277 /* allocate memory */
3278 sizeInBytes
= texture_size(texImage
);
3279 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3280 if (!texImage
->Data
) {
3281 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3285 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3286 pixels
, packing
, "glTexImage1D");
3288 /* Note: we check for a NULL image pointer here, _after_ we allocated
3289 * memory for the texture. That's what the GL spec calls for.
3294 const GLint dstRowStride
= 0;
3295 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3296 texImage
->TexFormat
,
3298 0, 0, 0, /* dstX/Y/Zoffset */
3300 texImage
->ImageOffsets
,
3302 format
, type
, pixels
, packing
);
3304 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3308 _mesa_unmap_teximage_pbo(ctx
, packing
);
3313 * This is the software fallback for Driver.TexImage2D()
3314 * and Driver.CopyTexImage2D().
3316 * This function is oriented toward storing images in main memory, rather
3317 * than VRAM. Device driver's can easily plug in their own replacement.
3319 * Note: width and height may be pre-convolved dimensions, but
3320 * texImage->Width and texImage->Height will be post-convolved dimensions.
3323 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3324 GLint internalFormat
,
3325 GLint width
, GLint height
, GLint border
,
3326 GLenum format
, GLenum type
, const void *pixels
,
3327 const struct gl_pixelstore_attrib
*packing
,
3328 struct gl_texture_object
*texObj
,
3329 struct gl_texture_image
*texImage
)
3334 /* allocate memory */
3335 sizeInBytes
= texture_size(texImage
);
3336 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3337 if (!texImage
->Data
) {
3338 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3342 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3343 pixels
, packing
, "glTexImage2D");
3345 /* Note: we check for a NULL image pointer here, _after_ we allocated
3346 * memory for the texture. That's what the GL spec calls for.
3351 GLint dstRowStride
= texture_row_stride(texImage
);
3352 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3353 texImage
->TexFormat
,
3355 0, 0, 0, /* dstX/Y/Zoffset */
3357 texImage
->ImageOffsets
,
3359 format
, type
, pixels
, packing
);
3361 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3365 _mesa_unmap_teximage_pbo(ctx
, packing
);
3371 * This is the software fallback for Driver.TexImage3D()
3372 * and Driver.CopyTexImage3D().
3373 * \sa _mesa_store_teximage2d()
3376 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3377 GLint internalFormat
,
3378 GLint width
, GLint height
, GLint depth
, GLint border
,
3379 GLenum format
, GLenum type
, const void *pixels
,
3380 const struct gl_pixelstore_attrib
*packing
,
3381 struct gl_texture_object
*texObj
,
3382 struct gl_texture_image
*texImage
)
3387 /* allocate memory */
3388 sizeInBytes
= texture_size(texImage
);
3389 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3390 if (!texImage
->Data
) {
3391 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3395 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3396 type
, pixels
, packing
, "glTexImage3D");
3398 /* Note: we check for a NULL image pointer here, _after_ we allocated
3399 * memory for the texture. That's what the GL spec calls for.
3404 GLint dstRowStride
= texture_row_stride(texImage
);
3405 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3406 texImage
->TexFormat
,
3408 0, 0, 0, /* dstX/Y/Zoffset */
3410 texImage
->ImageOffsets
,
3411 width
, height
, depth
,
3412 format
, type
, pixels
, packing
);
3414 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3418 _mesa_unmap_teximage_pbo(ctx
, packing
);
3425 * This is the software fallback for Driver.TexSubImage1D()
3426 * and Driver.CopyTexSubImage1D().
3429 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3430 GLint xoffset
, GLint width
,
3431 GLenum format
, GLenum type
, const void *pixels
,
3432 const struct gl_pixelstore_attrib
*packing
,
3433 struct gl_texture_object
*texObj
,
3434 struct gl_texture_image
*texImage
)
3436 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3437 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3438 pixels
, packing
, "glTexSubImage1D");
3443 const GLint dstRowStride
= 0;
3444 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3445 texImage
->TexFormat
,
3447 xoffset
, 0, 0, /* offsets */
3449 texImage
->ImageOffsets
,
3451 format
, type
, pixels
, packing
);
3453 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
3457 _mesa_unmap_teximage_pbo(ctx
, packing
);
3463 * This is the software fallback for Driver.TexSubImage2D()
3464 * and Driver.CopyTexSubImage2D().
3467 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3468 GLint xoffset
, GLint yoffset
,
3469 GLint width
, GLint height
,
3470 GLenum format
, GLenum type
, const void *pixels
,
3471 const struct gl_pixelstore_attrib
*packing
,
3472 struct gl_texture_object
*texObj
,
3473 struct gl_texture_image
*texImage
)
3475 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3476 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3477 pixels
, packing
, "glTexSubImage2D");
3482 GLint dstRowStride
= texture_row_stride(texImage
);
3483 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3484 texImage
->TexFormat
,
3486 xoffset
, yoffset
, 0,
3488 texImage
->ImageOffsets
,
3490 format
, type
, pixels
, packing
);
3492 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
3496 _mesa_unmap_teximage_pbo(ctx
, packing
);
3501 * This is the software fallback for Driver.TexSubImage3D().
3502 * and Driver.CopyTexSubImage3D().
3505 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3506 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3507 GLint width
, GLint height
, GLint depth
,
3508 GLenum format
, GLenum type
, const void *pixels
,
3509 const struct gl_pixelstore_attrib
*packing
,
3510 struct gl_texture_object
*texObj
,
3511 struct gl_texture_image
*texImage
)
3513 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3514 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3515 type
, pixels
, packing
,
3521 GLint dstRowStride
= texture_row_stride(texImage
);
3522 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3523 texImage
->TexFormat
,
3525 xoffset
, yoffset
, zoffset
,
3527 texImage
->ImageOffsets
,
3528 width
, height
, depth
,
3529 format
, type
, pixels
, packing
);
3531 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
3535 _mesa_unmap_teximage_pbo(ctx
, packing
);
3540 * Fallback for Driver.CompressedTexImage1D()
3543 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3544 GLint internalFormat
,
3545 GLint width
, GLint border
,
3546 GLsizei imageSize
, const GLvoid
*data
,
3547 struct gl_texture_object
*texObj
,
3548 struct gl_texture_image
*texImage
)
3550 /* this space intentionally left blank */
3552 (void) target
; (void) level
;
3553 (void) internalFormat
;
3554 (void) width
; (void) border
;
3555 (void) imageSize
; (void) data
;
3563 * Fallback for Driver.CompressedTexImage2D()
3566 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3567 GLint internalFormat
,
3568 GLint width
, GLint height
, GLint border
,
3569 GLsizei imageSize
, const GLvoid
*data
,
3570 struct gl_texture_object
*texObj
,
3571 struct gl_texture_image
*texImage
)
3573 (void) width
; (void) height
; (void) border
;
3575 /* This is pretty simple, basically just do a memcpy without worrying
3576 * about the usual image unpacking or image transfer operations.
3580 ASSERT(texImage
->Width
> 0);
3581 ASSERT(texImage
->Height
> 0);
3582 ASSERT(texImage
->Depth
== 1);
3583 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
3585 /* allocate storage */
3586 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
3587 if (!texImage
->Data
) {
3588 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
3592 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3594 "glCompressedTexImage2D");
3599 MEMCPY(texImage
->Data
, data
, imageSize
);
3601 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3607 * Fallback for Driver.CompressedTexImage3D()
3610 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3611 GLint internalFormat
,
3612 GLint width
, GLint height
, GLint depth
,
3614 GLsizei imageSize
, const GLvoid
*data
,
3615 struct gl_texture_object
*texObj
,
3616 struct gl_texture_image
*texImage
)
3618 /* this space intentionally left blank */
3620 (void) target
; (void) level
;
3621 (void) internalFormat
;
3622 (void) width
; (void) height
; (void) depth
;
3624 (void) imageSize
; (void) data
;
3632 * Fallback for Driver.CompressedTexSubImage1D()
3635 _mesa_store_compressed_texsubimage1d(GLcontext
*ctx
, GLenum target
,
3637 GLint xoffset
, GLsizei width
,
3639 GLsizei imageSize
, const GLvoid
*data
,
3640 struct gl_texture_object
*texObj
,
3641 struct gl_texture_image
*texImage
)
3643 /* there are no compressed 1D texture formats yet */
3645 (void) target
; (void) level
;
3646 (void) xoffset
; (void) width
;
3648 (void) imageSize
; (void) data
;
3655 * Fallback for Driver.CompressedTexSubImage2D()
3658 _mesa_store_compressed_texsubimage2d(GLcontext
*ctx
, GLenum target
,
3660 GLint xoffset
, GLint yoffset
,
3661 GLsizei width
, GLsizei height
,
3663 GLsizei imageSize
, const GLvoid
*data
,
3664 struct gl_texture_object
*texObj
,
3665 struct gl_texture_image
*texImage
)
3667 GLint bytesPerRow
, destRowStride
, srcRowStride
;
3671 const gl_format texFormat
= texImage
->TexFormat
;
3672 const GLint destWidth
= texImage
->Width
;
3675 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3680 /* these should have been caught sooner */
3681 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
3682 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
3683 ASSERT((xoffset
% bw
) == 0);
3684 ASSERT((yoffset
% bh
) == 0);
3686 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3687 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3689 "glCompressedTexSubImage2D");
3693 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
3694 src
= (const GLubyte
*) data
;
3696 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
3697 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
3698 texFormat
, destWidth
,
3699 (GLubyte
*) texImage
->Data
);
3701 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
3702 rows
= height
/ bh
; /* rows in blocks */
3704 /* copy rows of blocks */
3705 for (i
= 0; i
< rows
; i
++) {
3706 MEMCPY(dest
, src
, bytesPerRow
);
3707 dest
+= destRowStride
;
3708 src
+= srcRowStride
;
3711 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3716 * Fallback for Driver.CompressedTexSubImage3D()
3719 _mesa_store_compressed_texsubimage3d(GLcontext
*ctx
, GLenum target
,
3721 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3722 GLsizei width
, GLsizei height
, GLsizei depth
,
3724 GLsizei imageSize
, const GLvoid
*data
,
3725 struct gl_texture_object
*texObj
,
3726 struct gl_texture_image
*texImage
)
3728 /* there are no compressed 3D texture formats yet */
3730 (void) target
; (void) level
;
3731 (void) xoffset
; (void) yoffset
; (void) zoffset
;
3732 (void) width
; (void) height
; (void) depth
;
3734 (void) imageSize
; (void) data
;