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
));
601 for (img
= 0; img
< srcDepth
; img
++) {
602 const GLint srcStride
=
603 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
605 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
609 for (row
= 0; row
< srcHeight
; row
++) {
610 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
611 srcFormat
, srcType
, src
, srcPacking
,
613 dst
+= srcWidth
* components
;
618 /* If we made a temporary image for convolution, free it here */
620 _mesa_free((void *) srcAddr
);
623 if (logicalBaseFormat
!= textureBaseFormat
) {
624 /* one more conversion step */
625 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
626 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
631 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
632 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
633 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
635 /* The actual texture format should have at least as many components
636 * as the logical texture format.
638 ASSERT(texComponents
>= logComponents
);
640 newImage
= (GLchan
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
641 * texComponents
* sizeof(GLchan
));
643 _mesa_free(tempImage
);
647 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
649 n
= srcWidth
* srcHeight
* srcDepth
;
650 for (i
= 0; i
< n
; i
++) {
652 for (k
= 0; k
< texComponents
; k
++) {
655 newImage
[i
* texComponents
+ k
] = 0;
657 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
659 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
663 _mesa_free(tempImage
);
664 tempImage
= newImage
;
672 * Copy GLubyte pixels from <src> to <dst> with swizzling.
673 * \param dst destination pixels
674 * \param dstComponents number of color components in destination pixels
675 * \param src source pixels
676 * \param srcComponents number of color components in source pixels
677 * \param map the swizzle mapping. map[X] says where to find the X component
678 * in the source image's pixels. For example, if the source image
679 * is GL_BGRA and X = red, map[0] yields 2.
680 * \param count number of pixels to copy/swizzle.
683 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
684 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
686 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
689 for (i = 0; i < count; i++) { \
691 if (srcComps == 4) { \
692 COPY_4UBV(tmp, src); \
695 for (j = 0; j < srcComps; j++) { \
700 for (j = 0; j < dstComps; j++) { \
701 dst[j] = tmp[map[j]]; \
712 ASSERT(srcComponents
<= 4);
713 ASSERT(dstComponents
<= 4);
715 switch (dstComponents
) {
717 switch (srcComponents
) {
719 SWZ_CPY(dst
, src
, count
, 4, 4);
722 SWZ_CPY(dst
, src
, count
, 4, 3);
725 SWZ_CPY(dst
, src
, count
, 4, 2);
728 SWZ_CPY(dst
, src
, count
, 4, 1);
735 switch (srcComponents
) {
737 SWZ_CPY(dst
, src
, count
, 3, 4);
740 SWZ_CPY(dst
, src
, count
, 3, 3);
743 SWZ_CPY(dst
, src
, count
, 3, 2);
746 SWZ_CPY(dst
, src
, count
, 3, 1);
753 switch (srcComponents
) {
755 SWZ_CPY(dst
, src
, count
, 2, 4);
758 SWZ_CPY(dst
, src
, count
, 2, 3);
761 SWZ_CPY(dst
, src
, count
, 2, 2);
764 SWZ_CPY(dst
, src
, count
, 2, 1);
771 switch (srcComponents
) {
773 SWZ_CPY(dst
, src
, count
, 1, 4);
776 SWZ_CPY(dst
, src
, count
, 1, 3);
779 SWZ_CPY(dst
, src
, count
, 1, 2);
782 SWZ_CPY(dst
, src
, count
, 1, 1);
796 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
797 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
799 /* Deal with the _REV input types:
801 static const GLubyte
*
802 type_mapping( GLenum srcType
)
806 case GL_UNSIGNED_BYTE
:
808 case GL_UNSIGNED_INT_8_8_8_8
:
809 return _mesa_little_endian() ? map_3210
: map_identity
;
810 case GL_UNSIGNED_INT_8_8_8_8_REV
:
811 return _mesa_little_endian() ? map_identity
: map_3210
;
817 /* Mapping required if input type is
819 static const GLubyte
*
820 byteswap_mapping( GLboolean swapBytes
,
828 case GL_UNSIGNED_BYTE
:
830 case GL_UNSIGNED_INT_8_8_8_8
:
831 case GL_UNSIGNED_INT_8_8_8_8_REV
:
841 * Transfer a GLubyte texture image with component swizzling.
844 _mesa_swizzle_ubyte_image(GLcontext
*ctx
,
849 GLenum baseInternalFormat
,
851 const GLubyte
*rgba2dst
,
852 GLuint dstComponents
,
855 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
857 const GLuint
*dstImageOffsets
,
859 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
860 const GLvoid
*srcAddr
,
861 const struct gl_pixelstore_attrib
*srcPacking
)
863 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
864 const GLubyte
*srctype2ubyte
, *swap
;
865 GLubyte map
[4], src2base
[6], base2rgba
[6];
867 const GLint srcRowStride
=
868 _mesa_image_row_stride(srcPacking
, srcWidth
,
869 srcFormat
, GL_UNSIGNED_BYTE
);
870 const GLint srcImageStride
871 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
873 const GLubyte
*srcImage
874 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
875 srcWidth
, srcHeight
, srcFormat
,
876 GL_UNSIGNED_BYTE
, 0, 0, 0);
880 /* Translate from src->baseInternal->GL_RGBA->dst. This will
881 * correctly deal with RGBA->RGB->RGBA conversions where the final
882 * A value must be 0xff regardless of the incoming alpha values.
884 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
885 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
886 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
887 srctype2ubyte
= type_mapping(srcType
);
890 for (i
= 0; i
< 4; i
++)
891 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
893 /* _mesa_printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
895 if (srcComponents
== dstComponents
&&
896 srcRowStride
== dstRowStride
&&
897 srcRowStride
== srcWidth
* srcComponents
&&
899 /* 1 and 2D images only */
900 GLubyte
*dstImage
= (GLubyte
*) dstAddr
901 + dstYoffset
* dstRowStride
902 + dstXoffset
* dstComponents
;
903 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
904 srcWidth
* srcHeight
);
908 for (img
= 0; img
< srcDepth
; img
++) {
909 const GLubyte
*srcRow
= srcImage
;
910 GLubyte
*dstRow
= (GLubyte
*) dstAddr
911 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
912 + dstYoffset
* dstRowStride
913 + dstXoffset
* dstComponents
;
914 for (row
= 0; row
< srcHeight
; row
++) {
915 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
916 dstRow
+= dstRowStride
;
917 srcRow
+= srcRowStride
;
919 srcImage
+= srcImageStride
;
926 * Teximage storage routine for when a simple memcpy will do.
927 * No pixel transfer operations or special texel encodings allowed.
928 * 1D, 2D and 3D images supported.
931 memcpy_texture(GLcontext
*ctx
,
935 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
937 const GLuint
*dstImageOffsets
,
938 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
939 GLenum srcFormat
, GLenum srcType
,
940 const GLvoid
*srcAddr
,
941 const struct gl_pixelstore_attrib
*srcPacking
)
943 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
945 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
946 srcWidth
, srcHeight
, srcFormat
, srcType
);
947 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
948 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
949 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
950 const GLint bytesPerRow
= srcWidth
* texelBytes
;
953 /* XXX update/re-enable for dstImageOffsets array */
954 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
955 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
956 GLubyte
*dstImage
= (GLubyte
*) dstAddr
957 + dstZoffset
* dstImageStride
958 + dstYoffset
* dstRowStride
959 + dstXoffset
* texelBytes
;
961 if (dstRowStride
== srcRowStride
&&
962 dstRowStride
== bytesPerRow
&&
963 ((dstImageStride
== srcImageStride
&&
964 dstImageStride
== bytesPerImage
) ||
967 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
972 for (img
= 0; img
< srcDepth
; img
++) {
973 const GLubyte
*srcRow
= srcImage
;
974 GLubyte
*dstRow
= dstImage
;
975 for (row
= 0; row
< srcHeight
; row
++) {
976 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
977 dstRow
+= dstRowStride
;
978 srcRow
+= srcRowStride
;
980 srcImage
+= srcImageStride
;
981 dstImage
+= dstImageStride
;
987 for (img
= 0; img
< srcDepth
; img
++) {
988 const GLubyte
*srcRow
= srcImage
;
989 GLubyte
*dstRow
= (GLubyte
*) dstAddr
990 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
991 + dstYoffset
* dstRowStride
992 + dstXoffset
* texelBytes
;
993 for (row
= 0; row
< srcHeight
; row
++) {
994 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
995 dstRow
+= dstRowStride
;
996 srcRow
+= srcRowStride
;
998 srcImage
+= srcImageStride
;
1005 * Store a 32-bit integer depth component texture image.
1008 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1010 const GLuint depthScale
= 0xffffffff;
1011 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1013 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1014 ASSERT(texelBytes
== sizeof(GLuint
));
1016 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1017 ctx
->Pixel
.DepthBias
== 0.0f
&&
1018 !srcPacking
->SwapBytes
&&
1019 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1020 srcFormat
== GL_DEPTH_COMPONENT
&&
1021 srcType
== GL_UNSIGNED_INT
) {
1022 /* simple memcpy path */
1023 memcpy_texture(ctx
, dims
,
1024 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1027 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1028 srcAddr
, srcPacking
);
1033 for (img
= 0; img
< srcDepth
; img
++) {
1034 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1035 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1036 + dstYoffset
* dstRowStride
1037 + dstXoffset
* texelBytes
;
1038 for (row
= 0; row
< srcHeight
; row
++) {
1039 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1040 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1041 _mesa_unpack_depth_span(ctx
, srcWidth
,
1042 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1043 depthScale
, srcType
, src
, srcPacking
);
1044 dstRow
+= dstRowStride
;
1053 * Store a 24-bit integer depth component texture image.
1056 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1058 const GLuint depthScale
= 0xffffff;
1059 const GLuint texelBytes
= 4;
1062 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1067 for (img
= 0; img
< srcDepth
; img
++) {
1068 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1069 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1070 + dstYoffset
* dstRowStride
1071 + dstXoffset
* texelBytes
;
1072 for (row
= 0; row
< srcHeight
; row
++) {
1073 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1074 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1075 _mesa_unpack_depth_span(ctx
, srcWidth
,
1076 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1077 depthScale
, srcType
, src
, srcPacking
);
1078 dstRow
+= dstRowStride
;
1089 * Store a 16-bit integer depth component texture image.
1092 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1094 const GLuint depthScale
= 0xffff;
1095 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1097 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1098 ASSERT(texelBytes
== sizeof(GLushort
));
1100 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1101 ctx
->Pixel
.DepthBias
== 0.0f
&&
1102 !srcPacking
->SwapBytes
&&
1103 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1104 srcFormat
== GL_DEPTH_COMPONENT
&&
1105 srcType
== GL_UNSIGNED_SHORT
) {
1106 /* simple memcpy path */
1107 memcpy_texture(ctx
, dims
,
1108 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1111 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1112 srcAddr
, srcPacking
);
1117 for (img
= 0; img
< srcDepth
; img
++) {
1118 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1119 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1120 + dstYoffset
* dstRowStride
1121 + dstXoffset
* texelBytes
;
1122 for (row
= 0; row
< srcHeight
; row
++) {
1123 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1124 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1125 GLushort
*dst16
= (GLushort
*) dstRow
;
1126 _mesa_unpack_depth_span(ctx
, srcWidth
,
1127 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1128 srcType
, src
, srcPacking
);
1129 dstRow
+= dstRowStride
;
1138 * Store an rgb565 or rgb565_rev texture image.
1141 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1143 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1144 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1146 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1147 dstFormat
== MESA_FORMAT_RGB565_REV
);
1148 ASSERT(texelBytes
== 2);
1150 if (!ctx
->_ImageTransferState
&&
1151 !srcPacking
->SwapBytes
&&
1152 dstFormat
== MESA_FORMAT_RGB565
&&
1153 baseInternalFormat
== GL_RGB
&&
1154 srcFormat
== GL_RGB
&&
1155 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1156 /* simple memcpy path */
1157 memcpy_texture(ctx
, dims
,
1158 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1161 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1162 srcAddr
, srcPacking
);
1164 else if (!ctx
->_ImageTransferState
&&
1165 !srcPacking
->SwapBytes
&&
1166 baseInternalFormat
== GL_RGB
&&
1167 srcFormat
== GL_RGB
&&
1168 srcType
== GL_UNSIGNED_BYTE
&&
1170 /* do optimized tex store */
1171 const GLint srcRowStride
=
1172 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1173 const GLubyte
*src
= (const GLubyte
*)
1174 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1175 srcFormat
, srcType
, 0, 0, 0);
1176 GLubyte
*dst
= (GLubyte
*) dstAddr
1177 + dstYoffset
* dstRowStride
1178 + dstXoffset
* texelBytes
;
1180 for (row
= 0; row
< srcHeight
; row
++) {
1181 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1182 GLushort
*dstUS
= (GLushort
*) dst
;
1183 /* check for byteswapped format */
1184 if (dstFormat
== MESA_FORMAT_RGB565
) {
1185 for (col
= 0; col
< srcWidth
; col
++) {
1186 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1191 for (col
= 0; col
< srcWidth
; col
++) {
1192 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1196 dst
+= dstRowStride
;
1197 src
+= srcRowStride
;
1202 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1205 srcWidth
, srcHeight
, srcDepth
,
1206 srcFormat
, srcType
, srcAddr
,
1208 const GLchan
*src
= tempImage
;
1209 GLint img
, row
, col
;
1212 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1213 for (img
= 0; img
< srcDepth
; img
++) {
1214 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1215 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1216 + dstYoffset
* dstRowStride
1217 + dstXoffset
* texelBytes
;
1218 for (row
= 0; row
< srcHeight
; row
++) {
1219 GLushort
*dstUS
= (GLushort
*) dstRow
;
1220 /* check for byteswapped format */
1221 if (dstFormat
== MESA_FORMAT_RGB565
) {
1222 for (col
= 0; col
< srcWidth
; col
++) {
1223 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1224 CHAN_TO_UBYTE(src
[GCOMP
]),
1225 CHAN_TO_UBYTE(src
[BCOMP
]) );
1230 for (col
= 0; col
< srcWidth
; col
++) {
1231 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1232 CHAN_TO_UBYTE(src
[GCOMP
]),
1233 CHAN_TO_UBYTE(src
[BCOMP
]) );
1237 dstRow
+= dstRowStride
;
1240 _mesa_free((void *) tempImage
);
1247 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1250 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1252 const GLboolean littleEndian
= _mesa_little_endian();
1253 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1254 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1256 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1257 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1258 ASSERT(texelBytes
== 4);
1260 if (!ctx
->_ImageTransferState
&&
1261 !srcPacking
->SwapBytes
&&
1262 dstFormat
== MESA_FORMAT_RGBA8888
&&
1263 baseInternalFormat
== GL_RGBA
&&
1264 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1265 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1266 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1267 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1268 /* simple memcpy path */
1269 memcpy_texture(ctx
, dims
,
1270 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1273 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1274 srcAddr
, srcPacking
);
1276 else if (!ctx
->_ImageTransferState
&&
1277 !srcPacking
->SwapBytes
&&
1278 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1279 baseInternalFormat
== GL_RGBA
&&
1280 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1281 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1282 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1283 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1284 /* simple memcpy path */
1285 memcpy_texture(ctx
, dims
,
1286 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1289 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1290 srcAddr
, srcPacking
);
1292 else if (!ctx
->_ImageTransferState
&&
1293 (srcType
== GL_UNSIGNED_BYTE
||
1294 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1295 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1296 can_swizzle(baseInternalFormat
) &&
1297 can_swizzle(srcFormat
)) {
1301 /* dstmap - how to swizzle from RGBA to dst format:
1303 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1304 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1317 _mesa_swizzle_ubyte_image(ctx
, dims
,
1322 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1323 dstRowStride
, dstImageOffsets
,
1324 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1329 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1332 srcWidth
, srcHeight
, srcDepth
,
1333 srcFormat
, srcType
, srcAddr
,
1335 const GLchan
*src
= tempImage
;
1336 GLint img
, row
, col
;
1339 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1340 for (img
= 0; img
< srcDepth
; img
++) {
1341 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1342 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1343 + dstYoffset
* dstRowStride
1344 + dstXoffset
* texelBytes
;
1345 for (row
= 0; row
< srcHeight
; row
++) {
1346 GLuint
*dstUI
= (GLuint
*) dstRow
;
1347 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1348 for (col
= 0; col
< srcWidth
; col
++) {
1349 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1350 CHAN_TO_UBYTE(src
[GCOMP
]),
1351 CHAN_TO_UBYTE(src
[BCOMP
]),
1352 CHAN_TO_UBYTE(src
[ACOMP
]) );
1357 for (col
= 0; col
< srcWidth
; col
++) {
1358 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1359 CHAN_TO_UBYTE(src
[GCOMP
]),
1360 CHAN_TO_UBYTE(src
[BCOMP
]),
1361 CHAN_TO_UBYTE(src
[ACOMP
]) );
1365 dstRow
+= dstRowStride
;
1368 _mesa_free((void *) tempImage
);
1375 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1377 const GLboolean littleEndian
= _mesa_little_endian();
1378 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1379 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1381 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1382 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1383 dstFormat
== MESA_FORMAT_XRGB8888
);
1384 ASSERT(texelBytes
== 4);
1386 if (!ctx
->_ImageTransferState
&&
1387 !srcPacking
->SwapBytes
&&
1388 (dstFormat
== MESA_FORMAT_ARGB8888
||
1389 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1390 baseInternalFormat
== GL_RGBA
&&
1391 srcFormat
== GL_BGRA
&&
1392 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1393 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1394 /* simple memcpy path (little endian) */
1395 memcpy_texture(ctx
, dims
,
1396 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1399 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1400 srcAddr
, srcPacking
);
1402 else if (!ctx
->_ImageTransferState
&&
1403 !srcPacking
->SwapBytes
&&
1404 dstFormat
== MESA_FORMAT_ARGB8888_REV
&&
1405 baseInternalFormat
== GL_RGBA
&&
1406 srcFormat
== GL_BGRA
&&
1407 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1408 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1409 /* simple memcpy path (big endian) */
1410 memcpy_texture(ctx
, dims
,
1411 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1414 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1415 srcAddr
, srcPacking
);
1417 else if (!ctx
->_ImageTransferState
&&
1418 !srcPacking
->SwapBytes
&&
1419 (dstFormat
== MESA_FORMAT_ARGB8888
||
1420 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1421 srcFormat
== GL_RGB
&&
1422 (baseInternalFormat
== GL_RGBA
||
1423 baseInternalFormat
== GL_RGB
) &&
1424 srcType
== GL_UNSIGNED_BYTE
) {
1426 for (img
= 0; img
< srcDepth
; img
++) {
1427 const GLint srcRowStride
=
1428 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1429 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1430 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1431 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1432 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1433 + dstYoffset
* dstRowStride
1434 + dstXoffset
* texelBytes
;
1435 for (row
= 0; row
< srcHeight
; row
++) {
1436 GLuint
*d4
= (GLuint
*) dstRow
;
1437 for (col
= 0; col
< srcWidth
; col
++) {
1438 d4
[col
] = PACK_COLOR_8888(0xff,
1439 srcRow
[col
* 3 + RCOMP
],
1440 srcRow
[col
* 3 + GCOMP
],
1441 srcRow
[col
* 3 + BCOMP
]);
1443 dstRow
+= dstRowStride
;
1444 srcRow
+= srcRowStride
;
1448 else if (!ctx
->_ImageTransferState
&&
1449 !srcPacking
->SwapBytes
&&
1450 dstFormat
== MESA_FORMAT_ARGB8888
&&
1451 srcFormat
== GL_RGBA
&&
1452 baseInternalFormat
== GL_RGBA
&&
1453 srcType
== GL_UNSIGNED_BYTE
) {
1454 /* same as above case, but src data has alpha too */
1455 GLint img
, row
, col
;
1456 /* For some reason, streaming copies to write-combined regions
1457 * are extremely sensitive to the characteristics of how the
1458 * source data is retrieved. By reordering the source reads to
1459 * be in-order, the speed of this operation increases by half.
1460 * Strangely the same isn't required for the RGB path, above.
1462 for (img
= 0; img
< srcDepth
; img
++) {
1463 const GLint srcRowStride
=
1464 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1465 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1466 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1467 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1468 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1469 + dstYoffset
* dstRowStride
1470 + dstXoffset
* texelBytes
;
1471 for (row
= 0; row
< srcHeight
; row
++) {
1472 GLuint
*d4
= (GLuint
*) dstRow
;
1473 for (col
= 0; col
< srcWidth
; col
++) {
1474 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1475 srcRow
[col
* 4 + RCOMP
],
1476 srcRow
[col
* 4 + GCOMP
],
1477 srcRow
[col
* 4 + BCOMP
]);
1479 dstRow
+= dstRowStride
;
1480 srcRow
+= srcRowStride
;
1484 else if (!ctx
->_ImageTransferState
&&
1485 (srcType
== GL_UNSIGNED_BYTE
||
1486 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1487 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1488 can_swizzle(baseInternalFormat
) &&
1489 can_swizzle(srcFormat
)) {
1493 /* dstmap - how to swizzle from RGBA to dst format:
1495 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1496 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1497 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
)) {
1498 dstmap
[3] = 3; /* alpha */
1499 dstmap
[2] = 0; /* red */
1500 dstmap
[1] = 1; /* green */
1501 dstmap
[0] = 2; /* blue */
1504 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1505 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1506 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1513 _mesa_swizzle_ubyte_image(ctx
, dims
,
1519 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1522 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1527 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1530 srcWidth
, srcHeight
, srcDepth
,
1531 srcFormat
, srcType
, srcAddr
,
1533 const GLchan
*src
= tempImage
;
1534 GLint img
, row
, col
;
1537 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1538 for (img
= 0; img
< srcDepth
; img
++) {
1539 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1540 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1541 + dstYoffset
* dstRowStride
1542 + dstXoffset
* texelBytes
;
1543 for (row
= 0; row
< srcHeight
; row
++) {
1544 GLuint
*dstUI
= (GLuint
*) dstRow
;
1545 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1546 for (col
= 0; col
< srcWidth
; col
++) {
1547 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1548 CHAN_TO_UBYTE(src
[RCOMP
]),
1549 CHAN_TO_UBYTE(src
[GCOMP
]),
1550 CHAN_TO_UBYTE(src
[BCOMP
]) );
1554 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1555 for (col
= 0; col
< srcWidth
; col
++) {
1556 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1557 CHAN_TO_UBYTE(src
[RCOMP
]),
1558 CHAN_TO_UBYTE(src
[GCOMP
]),
1559 CHAN_TO_UBYTE(src
[BCOMP
]) );
1564 for (col
= 0; col
< srcWidth
; col
++) {
1565 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1566 CHAN_TO_UBYTE(src
[RCOMP
]),
1567 CHAN_TO_UBYTE(src
[GCOMP
]),
1568 CHAN_TO_UBYTE(src
[BCOMP
]) );
1572 dstRow
+= dstRowStride
;
1575 _mesa_free((void *) tempImage
);
1582 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1584 const GLboolean littleEndian
= _mesa_little_endian();
1585 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1586 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1588 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1589 ASSERT(texelBytes
== 3);
1591 if (!ctx
->_ImageTransferState
&&
1592 !srcPacking
->SwapBytes
&&
1593 baseInternalFormat
== GL_RGB
&&
1594 srcFormat
== GL_BGR
&&
1595 srcType
== GL_UNSIGNED_BYTE
&&
1597 /* simple memcpy path */
1598 memcpy_texture(ctx
, dims
,
1599 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1602 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1603 srcAddr
, srcPacking
);
1605 else if (!ctx
->_ImageTransferState
&&
1606 !srcPacking
->SwapBytes
&&
1607 srcFormat
== GL_RGBA
&&
1608 srcType
== GL_UNSIGNED_BYTE
) {
1609 /* extract RGB from RGBA */
1610 GLint img
, row
, col
;
1611 for (img
= 0; img
< srcDepth
; img
++) {
1612 const GLint srcRowStride
=
1613 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1614 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1615 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1616 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1617 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1618 + dstYoffset
* dstRowStride
1619 + dstXoffset
* texelBytes
;
1620 for (row
= 0; row
< srcHeight
; row
++) {
1621 for (col
= 0; col
< srcWidth
; col
++) {
1622 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1623 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1624 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1626 dstRow
+= dstRowStride
;
1627 srcRow
+= srcRowStride
;
1631 else if (!ctx
->_ImageTransferState
&&
1632 srcType
== GL_UNSIGNED_BYTE
&&
1633 can_swizzle(baseInternalFormat
) &&
1634 can_swizzle(srcFormat
)) {
1638 /* dstmap - how to swizzle from RGBA to dst format:
1643 dstmap
[3] = ONE
; /* ? */
1645 _mesa_swizzle_ubyte_image(ctx
, dims
,
1650 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1651 dstRowStride
, dstImageOffsets
,
1652 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1657 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1660 srcWidth
, srcHeight
, srcDepth
,
1661 srcFormat
, srcType
, srcAddr
,
1663 const GLchan
*src
= (const GLchan
*) tempImage
;
1664 GLint img
, row
, col
;
1667 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1668 for (img
= 0; img
< srcDepth
; img
++) {
1669 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1670 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1671 + dstYoffset
* dstRowStride
1672 + dstXoffset
* texelBytes
;
1673 for (row
= 0; row
< srcHeight
; row
++) {
1676 for (col
= 0; col
< srcWidth
; col
++) {
1677 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1678 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1679 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1684 for (col
= 0; col
< srcWidth
; col
++) {
1685 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1686 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1687 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1692 for (col
= 0; col
< srcWidth
; col
++) {
1693 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1694 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1695 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1699 dstRow
+= dstRowStride
;
1702 _mesa_free((void *) tempImage
);
1709 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1711 const GLboolean littleEndian
= _mesa_little_endian();
1712 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1713 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1715 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1716 ASSERT(texelBytes
== 3);
1718 if (!ctx
->_ImageTransferState
&&
1719 !srcPacking
->SwapBytes
&&
1720 baseInternalFormat
== GL_RGB
&&
1721 srcFormat
== GL_RGB
&&
1722 srcType
== GL_UNSIGNED_BYTE
&&
1724 /* simple memcpy path */
1725 memcpy_texture(ctx
, dims
,
1726 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1729 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1730 srcAddr
, srcPacking
);
1732 else if (!ctx
->_ImageTransferState
&&
1733 !srcPacking
->SwapBytes
&&
1734 srcFormat
== GL_RGBA
&&
1735 srcType
== GL_UNSIGNED_BYTE
) {
1736 /* extract BGR from RGBA */
1738 for (img
= 0; img
< srcDepth
; img
++) {
1739 const GLint srcRowStride
=
1740 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1741 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1742 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1743 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1744 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1745 + dstYoffset
* dstRowStride
1746 + dstXoffset
* texelBytes
;
1747 for (row
= 0; row
< srcHeight
; row
++) {
1748 for (col
= 0; col
< srcWidth
; col
++) {
1749 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1750 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1751 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1753 dstRow
+= dstRowStride
;
1754 srcRow
+= srcRowStride
;
1758 else if (!ctx
->_ImageTransferState
&&
1759 srcType
== GL_UNSIGNED_BYTE
&&
1760 can_swizzle(baseInternalFormat
) &&
1761 can_swizzle(srcFormat
)) {
1765 /* dstmap - how to swizzle from RGBA to dst format:
1770 dstmap
[3] = ONE
; /* ? */
1772 _mesa_swizzle_ubyte_image(ctx
, dims
,
1777 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1778 dstRowStride
, dstImageOffsets
,
1779 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1784 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1787 srcWidth
, srcHeight
, srcDepth
,
1788 srcFormat
, srcType
, srcAddr
,
1790 const GLchan
*src
= (const GLchan
*) tempImage
;
1791 GLint img
, row
, col
;
1794 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1795 for (img
= 0; img
< srcDepth
; img
++) {
1796 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1797 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1798 + dstYoffset
* dstRowStride
1799 + dstXoffset
* texelBytes
;
1800 for (row
= 0; row
< srcHeight
; row
++) {
1801 for (col
= 0; col
< srcWidth
; col
++) {
1802 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1803 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1804 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1807 dstRow
+= dstRowStride
;
1810 _mesa_free((void *) tempImage
);
1817 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1819 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1820 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1822 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1823 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1824 ASSERT(texelBytes
== 2);
1826 if (!ctx
->_ImageTransferState
&&
1827 !srcPacking
->SwapBytes
&&
1828 dstFormat
== MESA_FORMAT_ARGB4444
&&
1829 baseInternalFormat
== GL_RGBA
&&
1830 srcFormat
== GL_BGRA
&&
1831 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1832 /* simple memcpy path */
1833 memcpy_texture(ctx
, dims
,
1834 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1837 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1838 srcAddr
, srcPacking
);
1842 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1845 srcWidth
, srcHeight
, srcDepth
,
1846 srcFormat
, srcType
, srcAddr
,
1848 const GLchan
*src
= tempImage
;
1849 GLint img
, row
, col
;
1852 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1853 for (img
= 0; img
< srcDepth
; img
++) {
1854 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1855 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1856 + dstYoffset
* dstRowStride
1857 + dstXoffset
* texelBytes
;
1858 for (row
= 0; row
< srcHeight
; row
++) {
1859 GLushort
*dstUS
= (GLushort
*) dstRow
;
1860 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1861 for (col
= 0; col
< srcWidth
; col
++) {
1862 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1863 CHAN_TO_UBYTE(src
[RCOMP
]),
1864 CHAN_TO_UBYTE(src
[GCOMP
]),
1865 CHAN_TO_UBYTE(src
[BCOMP
]) );
1870 for (col
= 0; col
< srcWidth
; col
++) {
1871 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1872 CHAN_TO_UBYTE(src
[RCOMP
]),
1873 CHAN_TO_UBYTE(src
[GCOMP
]),
1874 CHAN_TO_UBYTE(src
[BCOMP
]) );
1878 dstRow
+= dstRowStride
;
1881 _mesa_free((void *) tempImage
);
1887 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1889 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1890 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1892 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1893 ASSERT(texelBytes
== 2);
1895 if (!ctx
->_ImageTransferState
&&
1896 !srcPacking
->SwapBytes
&&
1897 dstFormat
== MESA_FORMAT_RGBA5551
&&
1898 baseInternalFormat
== GL_RGBA
&&
1899 srcFormat
== GL_RGBA
&&
1900 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1901 /* simple memcpy path */
1902 memcpy_texture(ctx
, dims
,
1903 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1906 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1907 srcAddr
, srcPacking
);
1911 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1914 srcWidth
, srcHeight
, srcDepth
,
1915 srcFormat
, srcType
, srcAddr
,
1917 const GLchan
*src
=tempImage
;
1918 GLint img
, row
, col
;
1921 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1922 for (img
= 0; img
< srcDepth
; img
++) {
1923 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1924 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1925 + dstYoffset
* dstRowStride
1926 + dstXoffset
* texelBytes
;
1927 for (row
= 0; row
< srcHeight
; row
++) {
1928 GLushort
*dstUS
= (GLushort
*) dstRow
;
1929 for (col
= 0; col
< srcWidth
; col
++) {
1930 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1931 CHAN_TO_UBYTE(src
[GCOMP
]),
1932 CHAN_TO_UBYTE(src
[BCOMP
]),
1933 CHAN_TO_UBYTE(src
[ACOMP
]) );
1936 dstRow
+= dstRowStride
;
1939 _mesa_free((void *) tempImage
);
1945 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1947 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1948 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1950 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1951 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1952 ASSERT(texelBytes
== 2);
1954 if (!ctx
->_ImageTransferState
&&
1955 !srcPacking
->SwapBytes
&&
1956 dstFormat
== MESA_FORMAT_ARGB1555
&&
1957 baseInternalFormat
== GL_RGBA
&&
1958 srcFormat
== GL_BGRA
&&
1959 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1960 /* simple memcpy path */
1961 memcpy_texture(ctx
, dims
,
1962 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1965 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1966 srcAddr
, srcPacking
);
1970 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1973 srcWidth
, srcHeight
, srcDepth
,
1974 srcFormat
, srcType
, srcAddr
,
1976 const GLchan
*src
=tempImage
;
1977 GLint img
, row
, col
;
1980 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1981 for (img
= 0; img
< srcDepth
; img
++) {
1982 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1983 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1984 + dstYoffset
* dstRowStride
1985 + dstXoffset
* texelBytes
;
1986 for (row
= 0; row
< srcHeight
; row
++) {
1987 GLushort
*dstUS
= (GLushort
*) dstRow
;
1988 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1989 for (col
= 0; col
< srcWidth
; col
++) {
1990 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
1991 CHAN_TO_UBYTE(src
[RCOMP
]),
1992 CHAN_TO_UBYTE(src
[GCOMP
]),
1993 CHAN_TO_UBYTE(src
[BCOMP
]) );
1998 for (col
= 0; col
< srcWidth
; col
++) {
1999 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
2000 CHAN_TO_UBYTE(src
[RCOMP
]),
2001 CHAN_TO_UBYTE(src
[GCOMP
]),
2002 CHAN_TO_UBYTE(src
[BCOMP
]) );
2006 dstRow
+= dstRowStride
;
2009 _mesa_free((void *) tempImage
);
2016 _mesa_texstore_al88(TEXSTORE_PARAMS
)
2018 const GLboolean littleEndian
= _mesa_little_endian();
2019 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2020 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2022 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2023 dstFormat
== MESA_FORMAT_AL88_REV
);
2024 ASSERT(texelBytes
== 2);
2026 if (!ctx
->_ImageTransferState
&&
2027 !srcPacking
->SwapBytes
&&
2028 dstFormat
== MESA_FORMAT_AL88
&&
2029 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2030 srcFormat
== GL_LUMINANCE_ALPHA
&&
2031 srcType
== GL_UNSIGNED_BYTE
&&
2033 /* simple memcpy path */
2034 memcpy_texture(ctx
, dims
,
2035 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2038 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2039 srcAddr
, srcPacking
);
2041 else if (!ctx
->_ImageTransferState
&&
2043 srcType
== GL_UNSIGNED_BYTE
&&
2044 can_swizzle(baseInternalFormat
) &&
2045 can_swizzle(srcFormat
)) {
2049 /* dstmap - how to swizzle from RGBA to dst format:
2051 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2052 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2060 dstmap
[2] = ZERO
; /* ? */
2061 dstmap
[3] = ONE
; /* ? */
2063 _mesa_swizzle_ubyte_image(ctx
, dims
,
2068 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2069 dstRowStride
, dstImageOffsets
,
2070 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2075 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2078 srcWidth
, srcHeight
, srcDepth
,
2079 srcFormat
, srcType
, srcAddr
,
2081 const GLchan
*src
= tempImage
;
2082 GLint img
, row
, col
;
2085 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2086 for (img
= 0; img
< srcDepth
; img
++) {
2087 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2088 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2089 + dstYoffset
* dstRowStride
2090 + dstXoffset
* texelBytes
;
2091 for (row
= 0; row
< srcHeight
; row
++) {
2092 GLushort
*dstUS
= (GLushort
*) dstRow
;
2093 if (dstFormat
== MESA_FORMAT_AL88
) {
2094 for (col
= 0; col
< srcWidth
; col
++) {
2095 /* src[0] is luminance, src[1] is alpha */
2096 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2097 CHAN_TO_UBYTE(src
[0]) );
2102 for (col
= 0; col
< srcWidth
; col
++) {
2103 /* src[0] is luminance, src[1] is alpha */
2104 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2105 CHAN_TO_UBYTE(src
[0]) );
2109 dstRow
+= dstRowStride
;
2112 _mesa_free((void *) tempImage
);
2119 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2121 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2122 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2124 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2125 ASSERT(texelBytes
== 1);
2127 if (!ctx
->_ImageTransferState
&&
2128 !srcPacking
->SwapBytes
&&
2129 baseInternalFormat
== GL_RGB
&&
2130 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2131 /* simple memcpy path */
2132 memcpy_texture(ctx
, dims
,
2133 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2136 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2137 srcAddr
, srcPacking
);
2141 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2144 srcWidth
, srcHeight
, srcDepth
,
2145 srcFormat
, srcType
, srcAddr
,
2147 const GLchan
*src
= tempImage
;
2148 GLint img
, row
, col
;
2151 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2152 for (img
= 0; img
< srcDepth
; img
++) {
2153 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2154 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2155 + dstYoffset
* dstRowStride
2156 + dstXoffset
* texelBytes
;
2157 for (row
= 0; row
< srcHeight
; row
++) {
2158 for (col
= 0; col
< srcWidth
; col
++) {
2159 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2160 CHAN_TO_UBYTE(src
[GCOMP
]),
2161 CHAN_TO_UBYTE(src
[BCOMP
]) );
2164 dstRow
+= dstRowStride
;
2167 _mesa_free((void *) tempImage
);
2174 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2177 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2179 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2180 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2182 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2183 dstFormat
== MESA_FORMAT_L8
||
2184 dstFormat
== MESA_FORMAT_I8
);
2185 ASSERT(texelBytes
== 1);
2187 if (!ctx
->_ImageTransferState
&&
2188 !srcPacking
->SwapBytes
&&
2189 baseInternalFormat
== srcFormat
&&
2190 srcType
== GL_UNSIGNED_BYTE
) {
2191 /* simple memcpy path */
2192 memcpy_texture(ctx
, dims
,
2193 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2196 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2197 srcAddr
, srcPacking
);
2199 else if (!ctx
->_ImageTransferState
&&
2200 srcType
== GL_UNSIGNED_BYTE
&&
2201 can_swizzle(baseInternalFormat
) &&
2202 can_swizzle(srcFormat
)) {
2206 /* dstmap - how to swizzle from RGBA to dst format:
2208 if (dstFormat
== MESA_FORMAT_A8
) {
2214 dstmap
[1] = ZERO
; /* ? */
2215 dstmap
[2] = ZERO
; /* ? */
2216 dstmap
[3] = ONE
; /* ? */
2218 _mesa_swizzle_ubyte_image(ctx
, dims
,
2223 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2224 dstRowStride
, dstImageOffsets
,
2225 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2230 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2233 srcWidth
, srcHeight
, srcDepth
,
2234 srcFormat
, srcType
, srcAddr
,
2236 const GLchan
*src
= tempImage
;
2237 GLint img
, row
, col
;
2240 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2241 for (img
= 0; img
< srcDepth
; img
++) {
2242 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2243 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2244 + dstYoffset
* dstRowStride
2245 + dstXoffset
* texelBytes
;
2246 for (row
= 0; row
< srcHeight
; row
++) {
2247 for (col
= 0; col
< srcWidth
; col
++) {
2248 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2250 dstRow
+= dstRowStride
;
2254 _mesa_free((void *) tempImage
);
2262 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2264 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2266 (void) dims
; (void) baseInternalFormat
;
2267 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2268 ASSERT(texelBytes
== 1);
2269 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2271 if (!ctx
->_ImageTransferState
&&
2272 !srcPacking
->SwapBytes
&&
2273 srcFormat
== GL_COLOR_INDEX
&&
2274 srcType
== GL_UNSIGNED_BYTE
) {
2275 /* simple memcpy path */
2276 memcpy_texture(ctx
, dims
,
2277 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2280 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2281 srcAddr
, srcPacking
);
2286 for (img
= 0; img
< srcDepth
; img
++) {
2287 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2288 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2289 + dstYoffset
* dstRowStride
2290 + dstXoffset
* texelBytes
;
2291 for (row
= 0; row
< srcHeight
; row
++) {
2292 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2293 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2294 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2295 srcType
, src
, srcPacking
,
2296 ctx
->_ImageTransferState
);
2297 dstRow
+= dstRowStride
;
2306 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2309 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2311 const GLboolean littleEndian
= _mesa_little_endian();
2312 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2314 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2316 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2317 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2318 ASSERT(texelBytes
== 2);
2319 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2320 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2321 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2322 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2323 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2325 /* always just memcpy since no pixel transfer ops apply */
2326 memcpy_texture(ctx
, dims
,
2327 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2330 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2331 srcAddr
, srcPacking
);
2333 /* Check if we need byte swapping */
2334 /* XXX the logic here _might_ be wrong */
2335 if (srcPacking
->SwapBytes
^
2336 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2337 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2340 for (img
= 0; img
< srcDepth
; img
++) {
2341 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2342 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2343 + dstYoffset
* dstRowStride
2344 + dstXoffset
* texelBytes
;
2345 for (row
= 0; row
< srcHeight
; row
++) {
2346 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2347 dstRow
+= dstRowStride
;
2355 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2357 const GLboolean littleEndian
= _mesa_little_endian();
2358 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2360 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2361 ASSERT(texelBytes
== 2);
2362 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2363 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2364 (srcFormat
== GL_DUDV_ATI
));
2365 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2367 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2369 /* simple memcpy path */
2370 memcpy_texture(ctx
, dims
,
2371 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2374 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2375 srcAddr
, srcPacking
);
2377 else if (srcType
== GL_BYTE
) {
2381 /* dstmap - how to swizzle from RGBA to dst format:
2391 dstmap
[2] = ZERO
; /* ? */
2392 dstmap
[3] = ONE
; /* ? */
2394 _mesa_swizzle_ubyte_image(ctx
, dims
,
2395 GL_LUMINANCE_ALPHA
, /* hack */
2396 GL_UNSIGNED_BYTE
, /* hack */
2397 GL_LUMINANCE_ALPHA
, /* hack */
2399 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2400 dstRowStride
, dstImageOffsets
,
2401 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2405 /* general path - note this is defined for 2d textures only */
2406 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2407 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2408 srcFormat
, srcType
);
2409 GLbyte
*tempImage
, *dst
, *src
;
2412 tempImage
= (GLbyte
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
2413 * components
* sizeof(GLbyte
));
2417 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2418 srcWidth
, srcHeight
,
2423 for (row
= 0; row
< srcHeight
; row
++) {
2424 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2425 dst
, srcFormat
, srcType
, src
,
2427 dst
+= srcWidth
* components
;
2432 dst
= (GLbyte
*) dstAddr
2433 + dstYoffset
* dstRowStride
2434 + dstXoffset
* texelBytes
;
2435 for (row
= 0; row
< srcHeight
; row
++) {
2436 memcpy(dst
, src
, srcWidth
* texelBytes
);
2437 dst
+= dstRowStride
;
2438 src
+= srcWidth
* texelBytes
;
2440 _mesa_free((void *) tempImage
);
2446 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV
2449 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2451 const GLboolean littleEndian
= _mesa_little_endian();
2452 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2453 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2455 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2456 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2457 ASSERT(texelBytes
== 4);
2459 if (!ctx
->_ImageTransferState
&&
2460 !srcPacking
->SwapBytes
&&
2461 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2462 baseInternalFormat
== GL_RGBA
&&
2463 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2464 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2465 /* simple memcpy path */
2466 memcpy_texture(ctx
, dims
,
2467 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2470 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2471 srcAddr
, srcPacking
);
2473 else if (!ctx
->_ImageTransferState
&&
2474 !srcPacking
->SwapBytes
&&
2475 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2476 baseInternalFormat
== GL_RGBA
&&
2477 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2478 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2479 /* simple memcpy path */
2480 memcpy_texture(ctx
, dims
,
2481 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2484 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2485 srcAddr
, srcPacking
);
2487 else if (!ctx
->_ImageTransferState
&&
2488 (srcType
== GL_BYTE
) &&
2489 can_swizzle(baseInternalFormat
) &&
2490 can_swizzle(srcFormat
)) {
2494 /* dstmap - how to swizzle from RGBA to dst format:
2496 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2497 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2510 _mesa_swizzle_ubyte_image(ctx
, dims
,
2515 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2516 dstRowStride
, dstImageOffsets
,
2517 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2522 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2525 srcWidth
, srcHeight
, srcDepth
,
2526 srcFormat
, srcType
, srcAddr
,
2528 const GLfloat
*srcRow
= tempImage
;
2529 GLint img
, row
, col
;
2532 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2533 for (img
= 0; img
< srcDepth
; img
++) {
2534 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2535 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2536 + dstYoffset
* dstRowStride
2537 + dstXoffset
* texelBytes
;
2538 for (row
= 0; row
< srcHeight
; row
++) {
2539 GLuint
*dstUI
= (GLuint
*) dstRow
;
2540 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2541 for (col
= 0; col
< srcWidth
; col
++) {
2542 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2543 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2544 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2545 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2550 for (col
= 0; col
< srcWidth
; col
++) {
2551 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2552 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2553 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2554 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2558 dstRow
+= dstRowStride
;
2561 _mesa_free((void *) tempImage
);
2567 * Store a combined depth/stencil texture image.
2570 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2572 const GLfloat depthScale
= (GLfloat
) 0xffffff;
2573 const GLint srcRowStride
2574 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2578 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2579 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2580 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2582 /* In case we only upload depth we need to preserve the stencil */
2583 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2584 for (img
= 0; img
< srcDepth
; img
++) {
2585 GLuint
*dstRow
= (GLuint
*) dstAddr
2586 + dstImageOffsets
[dstZoffset
+ img
]
2587 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2590 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2591 srcWidth
, srcHeight
,
2594 for (row
= 0; row
< srcHeight
; row
++) {
2595 GLuint depth
[MAX_WIDTH
];
2597 _mesa_unpack_depth_span(ctx
, srcWidth
,
2598 GL_UNSIGNED_INT
, /* dst type */
2599 depth
, /* dst addr */
2601 srcType
, src
, srcPacking
);
2603 for (i
= 0; i
< srcWidth
; i
++)
2604 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2606 src
+= srcRowStride
;
2607 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2611 else if (ctx
->Pixel
.DepthScale
== 1.0f
&&
2612 ctx
->Pixel
.DepthBias
== 0.0f
&&
2613 !srcPacking
->SwapBytes
) {
2615 memcpy_texture(ctx
, dims
,
2616 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2619 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2620 srcAddr
, srcPacking
);
2624 const GLint srcRowStride
2625 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2629 for (img
= 0; img
< srcDepth
; img
++) {
2630 GLuint
*dstRow
= (GLuint
*) dstAddr
2631 + dstImageOffsets
[dstZoffset
+ img
]
2632 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2635 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2636 srcWidth
, srcHeight
,
2639 for (row
= 0; row
< srcHeight
; row
++) {
2640 GLubyte stencil
[MAX_WIDTH
];
2642 /* the 24 depth bits will be in the high position: */
2643 _mesa_unpack_depth_span(ctx
, srcWidth
,
2644 GL_UNSIGNED_INT_24_8_EXT
, /* dst type */
2645 dstRow
, /* dst addr */
2646 (GLuint
) depthScale
,
2647 srcType
, src
, srcPacking
);
2648 /* get the 8-bit stencil values */
2649 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2650 GL_UNSIGNED_BYTE
, /* dst type */
2651 stencil
, /* dst addr */
2652 srcType
, src
, srcPacking
,
2653 ctx
->_ImageTransferState
);
2654 /* merge stencil values into depth values */
2655 for (i
= 0; i
< srcWidth
; i
++)
2656 dstRow
[i
] |= stencil
[i
];
2658 src
+= srcRowStride
;
2659 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2668 * Store a combined depth/stencil texture image.
2671 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2673 const GLuint depthScale
= 0xffffff;
2674 const GLint srcRowStride
2675 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2679 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2680 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2681 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2683 /* In case we only upload depth we need to preserve the stencil */
2684 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2685 for (img
= 0; img
< srcDepth
; img
++) {
2686 GLuint
*dstRow
= (GLuint
*) dstAddr
2687 + dstImageOffsets
[dstZoffset
+ img
]
2688 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2691 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2692 srcWidth
, srcHeight
,
2695 for (row
= 0; row
< srcHeight
; row
++) {
2696 GLuint depth
[MAX_WIDTH
];
2698 _mesa_unpack_depth_span(ctx
, srcWidth
,
2699 GL_UNSIGNED_INT
, /* dst type */
2700 depth
, /* dst addr */
2702 srcType
, src
, srcPacking
);
2704 for (i
= 0; i
< srcWidth
; i
++)
2705 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2707 src
+= srcRowStride
;
2708 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2713 for (img
= 0; img
< srcDepth
; img
++) {
2714 GLuint
*dstRow
= (GLuint
*) dstAddr
2715 + dstImageOffsets
[dstZoffset
+ img
]
2716 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2719 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2720 srcWidth
, srcHeight
,
2723 for (row
= 0; row
< srcHeight
; row
++) {
2724 GLubyte stencil
[MAX_WIDTH
];
2726 /* the 24 depth bits will be in the low position: */
2727 _mesa_unpack_depth_span(ctx
, srcWidth
,
2728 GL_UNSIGNED_INT
, /* dst type */
2729 dstRow
, /* dst addr */
2731 srcType
, src
, srcPacking
);
2732 /* get the 8-bit stencil values */
2733 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2734 GL_UNSIGNED_BYTE
, /* dst type */
2735 stencil
, /* dst addr */
2736 srcType
, src
, srcPacking
,
2737 ctx
->_ImageTransferState
);
2738 /* merge stencil values into depth values */
2739 for (i
= 0; i
< srcWidth
; i
++)
2740 dstRow
[i
] |= stencil
[i
] << 24;
2742 src
+= srcRowStride
;
2743 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2751 * Store an image in any of the formats:
2752 * _mesa_texformat_rgba_float32
2753 * _mesa_texformat_rgb_float32
2754 * _mesa_texformat_alpha_float32
2755 * _mesa_texformat_luminance_float32
2756 * _mesa_texformat_luminance_alpha_float32
2757 * _mesa_texformat_intensity_float32
2760 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2762 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2763 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2764 const GLint components
= _mesa_components_in_format(baseFormat
);
2766 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2767 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2768 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
2769 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
2770 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
2771 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
2772 ASSERT(baseInternalFormat
== GL_RGBA
||
2773 baseInternalFormat
== GL_RGB
||
2774 baseInternalFormat
== GL_ALPHA
||
2775 baseInternalFormat
== GL_LUMINANCE
||
2776 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2777 baseInternalFormat
== GL_INTENSITY
);
2778 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
2780 if (!ctx
->_ImageTransferState
&&
2781 !srcPacking
->SwapBytes
&&
2782 baseInternalFormat
== srcFormat
&&
2783 srcType
== GL_FLOAT
) {
2784 /* simple memcpy path */
2785 memcpy_texture(ctx
, dims
,
2786 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2789 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2790 srcAddr
, srcPacking
);
2794 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2797 srcWidth
, srcHeight
, srcDepth
,
2798 srcFormat
, srcType
, srcAddr
,
2800 const GLfloat
*srcRow
= tempImage
;
2805 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2806 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2807 for (img
= 0; img
< srcDepth
; img
++) {
2808 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2809 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2810 + dstYoffset
* dstRowStride
2811 + dstXoffset
* texelBytes
;
2812 for (row
= 0; row
< srcHeight
; row
++) {
2813 _mesa_memcpy(dstRow
, srcRow
, bytesPerRow
);
2814 dstRow
+= dstRowStride
;
2815 srcRow
+= srcWidth
* components
;
2819 _mesa_free((void *) tempImage
);
2826 * As above, but store 16-bit floats.
2829 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2831 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2832 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2833 const GLint components
= _mesa_components_in_format(baseFormat
);
2835 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2836 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2837 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
2838 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
2839 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
2840 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
2841 ASSERT(baseInternalFormat
== GL_RGBA
||
2842 baseInternalFormat
== GL_RGB
||
2843 baseInternalFormat
== GL_ALPHA
||
2844 baseInternalFormat
== GL_LUMINANCE
||
2845 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2846 baseInternalFormat
== GL_INTENSITY
);
2847 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
2849 if (!ctx
->_ImageTransferState
&&
2850 !srcPacking
->SwapBytes
&&
2851 baseInternalFormat
== srcFormat
&&
2852 srcType
== GL_HALF_FLOAT_ARB
) {
2853 /* simple memcpy path */
2854 memcpy_texture(ctx
, dims
,
2855 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2858 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2859 srcAddr
, srcPacking
);
2863 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2866 srcWidth
, srcHeight
, srcDepth
,
2867 srcFormat
, srcType
, srcAddr
,
2869 const GLfloat
*src
= tempImage
;
2873 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2874 for (img
= 0; img
< srcDepth
; img
++) {
2875 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2876 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2877 + dstYoffset
* dstRowStride
2878 + dstXoffset
* texelBytes
;
2879 for (row
= 0; row
< srcHeight
; row
++) {
2880 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2882 for (i
= 0; i
< srcWidth
* components
; i
++) {
2883 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2885 dstRow
+= dstRowStride
;
2886 src
+= srcWidth
* components
;
2890 _mesa_free((void *) tempImage
);
2896 #if FEATURE_EXT_texture_sRGB
2898 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
2900 gl_format newDstFormat
;
2903 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
2905 /* reuse normal rgb texstore code */
2906 newDstFormat
= MESA_FORMAT_RGB888
;
2908 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
2909 newDstFormat
, dstAddr
,
2910 dstXoffset
, dstYoffset
, dstZoffset
,
2911 dstRowStride
, dstImageOffsets
,
2912 srcWidth
, srcHeight
, srcDepth
,
2914 srcAddr
, srcPacking
);
2920 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
2922 gl_format newDstFormat
;
2925 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
2927 /* reuse normal rgba texstore code */
2928 newDstFormat
= MESA_FORMAT_RGBA8888
;
2929 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
2930 newDstFormat
, dstAddr
,
2931 dstXoffset
, dstYoffset
, dstZoffset
,
2932 dstRowStride
, dstImageOffsets
,
2933 srcWidth
, srcHeight
, srcDepth
,
2935 srcAddr
, srcPacking
);
2941 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
2943 gl_format newDstFormat
;
2946 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
2948 /* reuse normal rgba texstore code */
2949 newDstFormat
= MESA_FORMAT_ARGB8888
;
2951 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
2952 newDstFormat
, dstAddr
,
2953 dstXoffset
, dstYoffset
, dstZoffset
,
2954 dstRowStride
, dstImageOffsets
,
2955 srcWidth
, srcHeight
, srcDepth
,
2957 srcAddr
, srcPacking
);
2963 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
2965 gl_format newDstFormat
;
2968 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
2970 newDstFormat
= MESA_FORMAT_L8
;
2972 /* _mesa_textore_a8 handles luminance8 too */
2973 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
2974 newDstFormat
, dstAddr
,
2975 dstXoffset
, dstYoffset
, dstZoffset
,
2976 dstRowStride
, dstImageOffsets
,
2977 srcWidth
, srcHeight
, srcDepth
,
2979 srcAddr
, srcPacking
);
2985 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
2987 gl_format newDstFormat
;
2990 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
2992 /* reuse normal luminance/alpha texstore code */
2993 newDstFormat
= MESA_FORMAT_AL88
;
2995 k
= _mesa_texstore_al88(ctx
, dims
, baseInternalFormat
,
2996 newDstFormat
, dstAddr
,
2997 dstXoffset
, dstYoffset
, dstZoffset
,
2998 dstRowStride
, dstImageOffsets
,
2999 srcWidth
, srcHeight
, srcDepth
,
3001 srcAddr
, srcPacking
);
3005 #endif /* FEATURE_EXT_texture_sRGB */
3011 * Table mapping MESA_FORMAT_8 to _mesa_texstore_*()
3012 * XXX this is somewhat temporary.
3016 StoreTexImageFunc Store
;
3018 texstore_funcs
[MESA_FORMAT_COUNT
] =
3020 { MESA_FORMAT_NONE
, NULL
},
3021 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
3022 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
3023 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
3024 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
3025 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
3026 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
3027 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
3028 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
3029 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
3030 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
3031 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
3032 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
3033 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
3034 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
3035 { MESA_FORMAT_AL88
, _mesa_texstore_al88
},
3036 { MESA_FORMAT_AL88_REV
, _mesa_texstore_al88
},
3037 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
3038 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
3039 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
3040 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
3041 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
3042 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
3043 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
3044 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
3045 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
3046 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3047 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
3048 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3049 { MESA_FORMAT_S8
, NULL
/*_mesa_texstore_s8*/ },
3050 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3051 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3052 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3053 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3054 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3055 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3056 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3057 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3058 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3059 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3060 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3061 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3062 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3063 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3064 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3065 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3066 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3067 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3068 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3069 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3070 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3071 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3072 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3073 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3074 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3075 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3076 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3077 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3078 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3079 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3080 { MESA_FORMAT_SIGNED_RGBA_16
, NULL
},
3085 * Return the StoreTexImageFunc pointer to store an image in the given format.
3087 static StoreTexImageFunc
3088 _mesa_get_texstore_func(gl_format format
)
3092 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
3093 ASSERT(texstore_funcs
[i
].Name
== i
);
3096 ASSERT(texstore_funcs
[format
].Name
== format
);
3097 return texstore_funcs
[format
].Store
;
3102 * Store user data into texture memory.
3103 * Called via glTex[Sub]Image1/2/3D()
3106 _mesa_texstore(TEXSTORE_PARAMS
)
3108 StoreTexImageFunc storeImage
;
3111 storeImage
= _mesa_get_texstore_func(dstFormat
);
3115 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3116 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3117 dstRowStride
, dstImageOffsets
,
3118 srcWidth
, srcHeight
, srcDepth
,
3119 srcFormat
, srcType
, srcAddr
, srcPacking
);
3125 * Check if an unpack PBO is active prior to fetching a texture image.
3126 * If so, do bounds checking and map the buffer into main memory.
3127 * Any errors detected will be recorded.
3128 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3131 _mesa_validate_pbo_teximage(GLcontext
*ctx
, GLuint dimensions
,
3132 GLsizei width
, GLsizei height
, GLsizei depth
,
3133 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3134 const struct gl_pixelstore_attrib
*unpack
,
3135 const char *funcName
)
3139 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
3143 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
3144 format
, type
, pixels
)) {
3145 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3149 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3150 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
3152 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3156 return ADD_POINTERS(buf
, pixels
);
3161 * Check if an unpack PBO is active prior to fetching a compressed texture
3163 * If so, do bounds checking and map the buffer into main memory.
3164 * Any errors detected will be recorded.
3165 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3168 _mesa_validate_pbo_compressed_teximage(GLcontext
*ctx
,
3169 GLsizei imageSize
, const GLvoid
*pixels
,
3170 const struct gl_pixelstore_attrib
*packing
,
3171 const char *funcName
)
3175 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
3176 /* not using a PBO - return pointer unchanged */
3179 if ((const GLubyte
*) pixels
+ imageSize
>
3180 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
3181 /* out of bounds read! */
3182 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3186 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3187 GL_READ_ONLY_ARB
, packing
->BufferObj
);
3189 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3193 return ADD_POINTERS(buf
, pixels
);
3198 * This function must be called after either of the validate_pbo_*_teximage()
3199 * functions. It unmaps the PBO buffer if it was mapped earlier.
3202 _mesa_unmap_teximage_pbo(GLcontext
*ctx
,
3203 const struct gl_pixelstore_attrib
*unpack
)
3205 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
3206 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3212 /** Return texture size in bytes */
3214 texture_size(const struct gl_texture_image
*texImage
)
3216 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
3217 texImage
->Height
, texImage
->Depth
);
3222 /** Return row stride in bytes */
3224 texture_row_stride(const struct gl_texture_image
*texImage
)
3226 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
3234 * This is the software fallback for Driver.TexImage1D()
3235 * and Driver.CopyTexImage1D().
3236 * \sa _mesa_store_teximage2d()
3237 * Note that the width may not be the actual texture width since it may
3238 * be changed by convolution w/ GL_REDUCE. The texImage->Width field will
3239 * have the actual texture size.
3242 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3243 GLint internalFormat
,
3244 GLint width
, GLint border
,
3245 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3246 const struct gl_pixelstore_attrib
*packing
,
3247 struct gl_texture_object
*texObj
,
3248 struct gl_texture_image
*texImage
)
3253 /* allocate memory */
3254 sizeInBytes
= texture_size(texImage
);
3255 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3256 if (!texImage
->Data
) {
3257 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3261 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3262 pixels
, packing
, "glTexImage1D");
3264 /* Note: we check for a NULL image pointer here, _after_ we allocated
3265 * memory for the texture. That's what the GL spec calls for.
3270 const GLint dstRowStride
= 0;
3271 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3272 texImage
->TexFormat
,
3274 0, 0, 0, /* dstX/Y/Zoffset */
3276 texImage
->ImageOffsets
,
3278 format
, type
, pixels
, packing
);
3280 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3284 _mesa_unmap_teximage_pbo(ctx
, packing
);
3289 * This is the software fallback for Driver.TexImage2D()
3290 * and Driver.CopyTexImage2D().
3292 * This function is oriented toward storing images in main memory, rather
3293 * than VRAM. Device driver's can easily plug in their own replacement.
3295 * Note: width and height may be pre-convolved dimensions, but
3296 * texImage->Width and texImage->Height will be post-convolved dimensions.
3299 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3300 GLint internalFormat
,
3301 GLint width
, GLint height
, GLint border
,
3302 GLenum format
, GLenum type
, const void *pixels
,
3303 const struct gl_pixelstore_attrib
*packing
,
3304 struct gl_texture_object
*texObj
,
3305 struct gl_texture_image
*texImage
)
3310 /* allocate memory */
3311 sizeInBytes
= texture_size(texImage
);
3312 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3313 if (!texImage
->Data
) {
3314 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3318 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3319 pixels
, packing
, "glTexImage2D");
3321 /* Note: we check for a NULL image pointer here, _after_ we allocated
3322 * memory for the texture. That's what the GL spec calls for.
3327 GLint dstRowStride
= texture_row_stride(texImage
);
3328 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3329 texImage
->TexFormat
,
3331 0, 0, 0, /* dstX/Y/Zoffset */
3333 texImage
->ImageOffsets
,
3335 format
, type
, pixels
, packing
);
3337 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3341 _mesa_unmap_teximage_pbo(ctx
, packing
);
3347 * This is the software fallback for Driver.TexImage3D()
3348 * and Driver.CopyTexImage3D().
3349 * \sa _mesa_store_teximage2d()
3352 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3353 GLint internalFormat
,
3354 GLint width
, GLint height
, GLint depth
, GLint border
,
3355 GLenum format
, GLenum type
, const void *pixels
,
3356 const struct gl_pixelstore_attrib
*packing
,
3357 struct gl_texture_object
*texObj
,
3358 struct gl_texture_image
*texImage
)
3363 /* allocate memory */
3364 sizeInBytes
= texture_size(texImage
);
3365 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3366 if (!texImage
->Data
) {
3367 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3371 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3372 type
, pixels
, packing
, "glTexImage3D");
3374 /* Note: we check for a NULL image pointer here, _after_ we allocated
3375 * memory for the texture. That's what the GL spec calls for.
3380 GLint dstRowStride
= texture_row_stride(texImage
);
3381 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3382 texImage
->TexFormat
,
3384 0, 0, 0, /* dstX/Y/Zoffset */
3386 texImage
->ImageOffsets
,
3387 width
, height
, depth
,
3388 format
, type
, pixels
, packing
);
3390 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3394 _mesa_unmap_teximage_pbo(ctx
, packing
);
3401 * This is the software fallback for Driver.TexSubImage1D()
3402 * and Driver.CopyTexSubImage1D().
3405 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3406 GLint xoffset
, GLint width
,
3407 GLenum format
, GLenum type
, const void *pixels
,
3408 const struct gl_pixelstore_attrib
*packing
,
3409 struct gl_texture_object
*texObj
,
3410 struct gl_texture_image
*texImage
)
3412 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3413 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3414 pixels
, packing
, "glTexSubImage1D");
3419 const GLint dstRowStride
= 0;
3420 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3421 texImage
->TexFormat
,
3423 xoffset
, 0, 0, /* offsets */
3425 texImage
->ImageOffsets
,
3427 format
, type
, pixels
, packing
);
3429 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
3433 _mesa_unmap_teximage_pbo(ctx
, packing
);
3439 * This is the software fallback for Driver.TexSubImage2D()
3440 * and Driver.CopyTexSubImage2D().
3443 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3444 GLint xoffset
, GLint yoffset
,
3445 GLint width
, GLint height
,
3446 GLenum format
, GLenum type
, const void *pixels
,
3447 const struct gl_pixelstore_attrib
*packing
,
3448 struct gl_texture_object
*texObj
,
3449 struct gl_texture_image
*texImage
)
3451 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3452 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3453 pixels
, packing
, "glTexSubImage2D");
3458 GLint dstRowStride
= texture_row_stride(texImage
);
3459 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3460 texImage
->TexFormat
,
3462 xoffset
, yoffset
, 0,
3464 texImage
->ImageOffsets
,
3466 format
, type
, pixels
, packing
);
3468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
3472 _mesa_unmap_teximage_pbo(ctx
, packing
);
3477 * This is the software fallback for Driver.TexSubImage3D().
3478 * and Driver.CopyTexSubImage3D().
3481 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3482 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3483 GLint width
, GLint height
, GLint depth
,
3484 GLenum format
, GLenum type
, const void *pixels
,
3485 const struct gl_pixelstore_attrib
*packing
,
3486 struct gl_texture_object
*texObj
,
3487 struct gl_texture_image
*texImage
)
3489 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3490 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3491 type
, pixels
, packing
,
3497 GLint dstRowStride
= texture_row_stride(texImage
);
3498 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3499 texImage
->TexFormat
,
3501 xoffset
, yoffset
, zoffset
,
3503 texImage
->ImageOffsets
,
3504 width
, height
, depth
,
3505 format
, type
, pixels
, packing
);
3507 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
3511 _mesa_unmap_teximage_pbo(ctx
, packing
);
3516 * Fallback for Driver.CompressedTexImage1D()
3519 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3520 GLint internalFormat
,
3521 GLint width
, GLint border
,
3522 GLsizei imageSize
, const GLvoid
*data
,
3523 struct gl_texture_object
*texObj
,
3524 struct gl_texture_image
*texImage
)
3526 /* this space intentionally left blank */
3528 (void) target
; (void) level
;
3529 (void) internalFormat
;
3530 (void) width
; (void) border
;
3531 (void) imageSize
; (void) data
;
3539 * Fallback for Driver.CompressedTexImage2D()
3542 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3543 GLint internalFormat
,
3544 GLint width
, GLint height
, GLint border
,
3545 GLsizei imageSize
, const GLvoid
*data
,
3546 struct gl_texture_object
*texObj
,
3547 struct gl_texture_image
*texImage
)
3549 (void) width
; (void) height
; (void) border
;
3551 /* This is pretty simple, basically just do a memcpy without worrying
3552 * about the usual image unpacking or image transfer operations.
3556 ASSERT(texImage
->Width
> 0);
3557 ASSERT(texImage
->Height
> 0);
3558 ASSERT(texImage
->Depth
== 1);
3559 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
3561 /* allocate storage */
3562 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
3563 if (!texImage
->Data
) {
3564 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
3568 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3570 "glCompressedTexImage2D");
3575 MEMCPY(texImage
->Data
, data
, imageSize
);
3577 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3583 * Fallback for Driver.CompressedTexImage3D()
3586 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3587 GLint internalFormat
,
3588 GLint width
, GLint height
, GLint depth
,
3590 GLsizei imageSize
, const GLvoid
*data
,
3591 struct gl_texture_object
*texObj
,
3592 struct gl_texture_image
*texImage
)
3594 /* this space intentionally left blank */
3596 (void) target
; (void) level
;
3597 (void) internalFormat
;
3598 (void) width
; (void) height
; (void) depth
;
3600 (void) imageSize
; (void) data
;
3608 * Fallback for Driver.CompressedTexSubImage1D()
3611 _mesa_store_compressed_texsubimage1d(GLcontext
*ctx
, GLenum target
,
3613 GLint xoffset
, GLsizei width
,
3615 GLsizei imageSize
, const GLvoid
*data
,
3616 struct gl_texture_object
*texObj
,
3617 struct gl_texture_image
*texImage
)
3619 /* there are no compressed 1D texture formats yet */
3621 (void) target
; (void) level
;
3622 (void) xoffset
; (void) width
;
3624 (void) imageSize
; (void) data
;
3631 * Fallback for Driver.CompressedTexSubImage2D()
3634 _mesa_store_compressed_texsubimage2d(GLcontext
*ctx
, GLenum target
,
3636 GLint xoffset
, GLint yoffset
,
3637 GLsizei width
, GLsizei height
,
3639 GLsizei imageSize
, const GLvoid
*data
,
3640 struct gl_texture_object
*texObj
,
3641 struct gl_texture_image
*texImage
)
3643 GLint bytesPerRow
, destRowStride
, srcRowStride
;
3647 const gl_format texFormat
= texImage
->TexFormat
;
3648 const GLint destWidth
= texImage
->Width
;
3651 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3656 /* these should have been caught sooner */
3657 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
3658 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
3659 ASSERT((xoffset
% bw
) == 0);
3660 ASSERT((yoffset
% bh
) == 0);
3662 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3663 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3665 "glCompressedTexSubImage2D");
3669 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
3670 src
= (const GLubyte
*) data
;
3672 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
3673 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
3674 texFormat
, destWidth
,
3675 (GLubyte
*) texImage
->Data
);
3677 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
3678 rows
= height
/ bh
; /* rows in blocks */
3680 /* copy rows of blocks */
3681 for (i
= 0; i
< rows
; i
++) {
3682 MEMCPY(dest
, src
, bytesPerRow
);
3683 dest
+= destRowStride
;
3684 src
+= srcRowStride
;
3687 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3692 * Fallback for Driver.CompressedTexSubImage3D()
3695 _mesa_store_compressed_texsubimage3d(GLcontext
*ctx
, GLenum target
,
3697 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3698 GLsizei width
, GLsizei height
, GLsizei depth
,
3700 GLsizei imageSize
, const GLvoid
*data
,
3701 struct gl_texture_object
*texObj
,
3702 struct gl_texture_image
*texImage
)
3704 /* there are no compressed 3D texture formats yet */
3706 (void) target
; (void) level
;
3707 (void) xoffset
; (void) yoffset
; (void) zoffset
;
3708 (void) width
; (void) height
; (void) depth
;
3710 (void) imageSize
; (void) data
;